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:
Thanks for your help,
Hani
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:
Thanks for your help,
Hani
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Line 19 has typo. Please change
FROM ce2;
to
FROM cte2;
FROM ce2;
to
FROM cte2;
ASKER
I will test and get back to you with feedback.
Best,
Hani