将Oracle查询转换为Hive

时间:2019-03-17 15:32:17

标签: oracle hive

如何将Oracle中的以下查询转换为Hive?

SELECT A.EMP_NO, A.LOGIN_TIMESTAMP FROM TABLE1 A, TABLE2 B 
WHERE A.EMP_NO = 1234 AND B.EMP_CURR = 
(SELECT MIN(EMP_CURR) FROM TABLE2 WHERE EMP_NO = A.EMP_NO AND 
LOGIN_TIMESTAMP = A.LOGIN_TIMESTAMP AND EMP_STATUS_CODE <> 'P')

1 个答案:

答案 0 :(得分:0)

使用dense_rank()获取最少包含EMP_CURR的行:

SELECT A.EMP_NO, A.LOGIN_TIMESTAMP
  FROM TABLE1 A
       INNER JOIN (select B.*, 
                          dense_rank() over(partition by B.EMP_NO, B.LOGIN_TIMESTAMP order by B.EMP_CURR) rn
                     from TABLE2 B where EMP_STATUS_CODE <> 'P'
                  ) B
                  on B.EMP_NO = A.EMP_NO and B.LOGIN_TIMESTAMP = A.LOGIN_TIMESTAMP and B.rn=1
  where B.rn=1 and A.EMP_NO = 1234;