Retrieving Top 10 rows ans sum all others in row 11
Posted
by Mario
on Stack Overflow
See other posts from Stack Overflow
or by Mario
Published on 2010-04-08T14:52:17Z
Indexed on
2010/04/08
14:53 UTC
Read the original article
Hit count: 250
sql-server-2005
Hello all, I have the following query that retrieve the number of users per country;
SELECT C.CountryID AS CountryID,
C.CountryName AS Country,
Count(FirstName) AS Origin
FROM Users AS U
INNER JOIN Country AS C ON C.CountryID = U.CountryOfOrgin
GROUP BY CASE C.CountryName,
C.CountryID
What I need is a way to get the top 10 and then sum all other users in a single row. I know how to get the top 10 but I`m stuck on getting the remaining in a single row. Is there a simple way to do it?
For example if the above query returns 17 records the top ten are displayed and a sum of the users from the 7 remaining country should appear on row 11. On that row 11 the countryid would be 0 and countryname Others
Thanks for your help!
© Stack Overflow or respective owner