I’m trying to get the top 50 cities for all customer lists in our DB
(So simplified: every client has a list of customers with associated data(like the city))
If I say:
SELECT top(50) clientid, city, COUNT(city) as cnt
FROM customers
GROUP BY clientid, city
ORDER by cnt
it will limit the total resultset on 50 rows instead of limiting the results for every group.
How can I get the top 50 per clientid?
EDIT:
I searched stackoverflow (and googled) but only found solutions for Mysql. Probably searching for ‘limit’ will only find mysql solutions wince thats the keyword needed for that Database engine. If I know the keyword needed in Sql-Server I could find it as well using google.
1 Answer