hive 取排行第二的工资
CREATE TABLE employee( id INT , salary INT ); INSERT INTO employee SELECT 1,100 UNION ALL SELECT 2,200 UNION ALL SELECT 3,300; SELECT coalesce(salary ,0) salary FROM ( SELECT id, salary, row_number() over( ORDER BY salary desc) num FROM ( SELECT id, salary, row_number() over( PARTITION BY(id) ORDER BY salary) AS n FROM employee ) a WHERE a.n = 1 ) b WHERE b.num = 2;
-----------------