我希望看到前50个国家/地区,其余国家/地区需要使用CASE语句与其他国家/地区分组。那有可能吗?请提出建议。
答案 0 :(得分:0)
您可以使用窗口函数和聚合来完成此操作
select (case when seqnum <= 50 then country else 'others' end) as country,
sum(?)
from (select t.*, row_number() over (order by ?) desc as seqnum
from t
) t
group by (case when seqnum <= 50 then country else 'others' end)
order by 2 desc;
?
用于您关注的列。