Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
This is my query.
SQL
SELECT top(10)  LocationName, companyname, COUNT(LocationName) AS TotalCount
FROM
Job where CountryId = 108 and LocationName !=' ' and CompanyName != ''
GROUP BY companyname ORDER BY TotalCount DESC

I want result like this.
XML
locationname   companyname count
hyderabad       IBM         45
Banglooru       Satyam      32

like this
my previous query

SELECT top(5) Locationname,
COUNT(Locationname) AS TotalCount
FROM
Job where CountryId = @cntid and Title !=' '
GROUP BY Locationname ORDER BY TotalCount DESC

this query result is

locationname    count
hyderabad          45
Banglooru          32

like this,
The first query is not working
please helpme.
Thank you.
Posted
Comments
Naz_Firdouse 27-May-14 6:24am    
not working in the sense???
can you show what output you are getting for the first query?
Bh@gyesh 27-May-14 6:25am    
Which error you got?
Add LocationName in Group By clause

1 solution

You were missing the LocationName in the Group BY clause


SELECT top(10) LocationName, companyname, COUNT(LocationName) AS TotalCount
FROM
Job where CountryId = 108 and LocationName !=' ' and CompanyName != ''
GROUP BY companyname, LocationName ORDER BY TotalCount DESC
 
Share this answer
 
v2
Comments
NagaRaju Pesarlanka 27-May-14 7:23am    
thank you...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900