1,窗口函数
举例:
create table company
(dep string, –部门
employ_id string, –员工id
salary double)–员工薪水
找出每个部门,薪水排名前三的员工id
hive,sql,mysql 。。。都适合用
select * from
(select dep ,employ_id , rank() over(partition by dep, order by salar desc) 排名 from company) temp
where 排名 in (1,2,3)
dep name salary rank
aa lyi 1000 1
aa lui 1040 2
aa ljfi 1040 2
abba lmnni 10120 1
abba lpl;i 10660 2
abba lbbdi 10760 3
ahha lbbi 1020 1
ahha lbi 10022 2
ahha lddi 10090 3
bb lwi 10560 1
bb lqqi 10560 1
bb lwsi 100900 3
rank() over(partition by dep, order by salar desc
窗口函数,在一般的函数后面加上over() ,这样这个函数的作用域就是在返回的结果集里面
over 里面一般搭配 partition by xxx, order by xxxx
如果是dense_rank() 的话就不会产生重复跳跃