Link to home
Start Free TrialLog in
Avatar of Mehawitchi
Mehawitchi

asked on

How to Club Rows in One Row As Others - SQL Server

Hello experts,

The following SQL query yields Results #1 (see below)

SELECT Top 10 ChGroupName AS GROUPNAME, SUM(SCORE) AS SCORE, RANK() OVER(ORDER BY SUM(SCORE) desc) AS RANKING
FROM SmryTable  
GROUP BY ChGroupName
ORDER BY RANKING


I need to alter the above query to make it list top 4 and club entries from 5 onwards as OTHERS, so that the results will look like the following:
User generated image
Thanks for your help,
Hani
ASKER CERTIFIED SOLUTION
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mehawitchi
Mehawitchi

ASKER

Thanks eghtebas - This looks promising.

I will test and get back to you with feedback.

Best,
Hani
Line 19 has typo. Please change

FROM ce2;

to

FROM cte2;