question

Sushant_Katte avatar image
Sushant_Katte asked

sql query to get the count from a column

I have a table with the following columns: SponsorID AccountID CountryID 123 456 236 123 789 236 123 654 40 123 897 236 123 978 40 123 564 40 ' ' ' ' ' ' ' ' ' I want to write a SQL query to find the sponsorIDs who have count of accounts having countryID = 40 more than 10 [ count(CountryID = 40) > 10 ]
sql-server-2008sql-server-2005sql-server-2008-r2sql-serversql-server-2012
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
happycat59 avatar image
happycat59 answered
You probably want something like... select sponsorid from yourtable where countryid =40 group by sponsorid having count(*) > 10
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.