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;

 

 

 

-----------------

Hive 使用datediff函数求两个指定日期的差

datediff(endDate, startDate)

posted @ 2019-08-30 10:48  消失的白桦林  阅读(543)  评论(0编辑  收藏  举报