窗口函数的应用
select job,
(case when max(t_rank)%2=1 then round((max(t_rank)+1)/2,0) else round(max(t_rank)/2,0) end) as start_rank,
(case when max(t_rank)%2=1 then round((max(t_rank)+1)/2,0) else round(max(t_rank)/2+1,0) end) as end_rank
from (select * , count(1) over (partition by job order by score ) as t_rank from grade) as a
group by job
order by job;
这道题学习到得最重要的是窗口函数的具体含义,虽然之前也使用过,但是并没有深入了解。
group by 是分组函数,用在过滤字段;
partition by 是分区函数,用在窗口函数中,大致作用与分组函数相同,不过只针对该窗口;
summ()等就是聚合函数。