June 30, 2008 at 4:54 pm
I need a query where i can group by OfficeName and also a count of them.
example:
EMpid Empname OfficeName
1 XXX CA
2 AAA OR
4 XXX OR
5 YYY WV
My result shud display OfficeName with its count.
OfficeName Count
OR 2
I am flexible to do this in sql 2005 also.
thanks
June 30, 2008 at 5:20 pm
OK I got that.
need to have count(*) after the group by column we need.
like
SELECT officename,count(*) as CountOfOffice FROM Emp
GROUP BY officename
July 2, 2008 at 3:17 am
To obtain your question's resulset, you must use the HAVING clause.
Somithing like this:
SELECT Field, Count(*) as NumberOfRecords
FROM Table
GROUP BY Field
HAVING COUNT(*) > 1
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply