I try to get the 50 best cities for all customer lists in our database (Itβs so simplified: each customer has a customer list with related data (for example, 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 overall result set to 50 rows instead of limiting the results for each group.
How can I get the top 50 customers?
EDIT: I was looking for stackoverflow (and googled), but found solutions for Mysql. Probably a βlimitβ search will only find mysql solutions, and this is the keyword needed for this database engine. If I know the keyword needed for Sql-Server, I could find it using google as well.
source share