After I ORDER BY cnt DESC
my results are
fld1 cnt
A 9
E 8
D 6
C 2
B 2
F 1
I need to have top 3 displayed and the rest to be summed as 'other', like this:
fld1 cnt
A 9
E 8
D 6
other 5
EDITED:
Thank you all for your input. Maybe it will help if you see the actual statement:
SELECT
CAST(u.FA AS VARCHAR(300)) AS FA,
COUNT(*) AS Total,
COUNT(CASE WHEN r.RT IN (1,11,12,17) THEN r.RT END) AS Jr,
COUNT(CASE WHEN r.RT IN (3,4,13) THEN r.RT END) AS Bk,
COUNT(CASE WHEN r.RT NOT IN (1,11,12,17,3,4,13) THEN r.RT END ) AS Other
FROM R r
INNER JOIN DB..RTL rt
ON r.RT = rt.RTID
INNER JOIN U u
ON r.UID = u.UID
WHERE rt.LC = 'en'
GROUP BY CAST(u.FA AS VARCHAR(300))--FA is ntext
ORDER BY Total DESC
The produced result has 19 records. I need to show the top 5 and sum up the rest as "Other FA". I don't want to do a select from a select from a select with this kind of statement. I am more looking for some SQL function. Maybe ROW_NUMBER is good idea, but I don't know how exactly to apply it in this case.