SQL Basics: Simple table totaling

* *
链接 SQL Basics: Simple table totaling
难度 6kyu
状态
日期 2019-4-28

题意

题解1

select rank () over (order by (total_points) desc)as rank, a.*
from (
select distinct (case when (clan ='') then '[no clan specified]' else clan end)as clan,
sum(points) as total_points,
count(distinct name) as total_people
from people
group by clan)a

题解2-wrong

select rank () over (order by (total_points) desc)as rank, a.*
from (
select distinct replace('clan','','no clan specified') as clan,
sum(points) as total_points,
count(distinct name) as total_people
from people
group by clan)a

题解-LZY

select rank() over (order by sum(points) desc) as rank, 
CASE WHEN clan IS NULL OR clan='' THEN '[no clan specified]' ELSE clan END,
sum(points) as total_points, count(*) as total_people
from people
group by clan
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容