Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 finding the count

Author  Topic 

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2012-02-27 : 21:40:45
Hi All,

I have following data in the table pls help me to get the result set shown below.

enquiry_id userid
123 100
457 100
100 100
102 500
107 500

Output result

userid enquiry_count
100 3
500 2


-Gangadhara

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-27 : 21:51:39
its just as simple as


SELECT userid,COUNT(enquiry_id) AS enquiry_count
FROM table
GROUP BY userid

Its a bit surprising that even after reaching 400 + posts you still doesnt seem to know simple GROUPing concepts

suggest you read this

http://www.w3schools.com/sql/sql_groupby.asp

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -