HiveQL 从员工table 中找到第二大薪水?

HiveQL to find the second largest salary from the employee table?

如何使用 HiveQl 从员工 table 中找到第二大薪水?

我自己得到了答案。下面是从 Employee table.

获取第二个最高薪水的 HQL 查询
select firstname,salary from
    (select firstname, salary from employee sort by salary desc limit 2)
     result sort by salary limit 1;

学习愉快!!

    SELECT * from(select salary,row_number( ) 
    over (order by salary desc ) 
    as BLAH_no from table where group by salary) T where T.BLAH_no=2;

如果出现平局,则接受的答案将无效。所以下面是我的代码,适用于所有情况。只需将 row_number 替换为 dense_rank 即可。想了解更多关于 dense_rank 然后访问这个 link

select * from  (SELECT dep_name,salary,DENSE_RANK() over(ORDER BY salary desc) as rank FROM department) as A where rank = 2;

输出:

+--------+------+----------+
|dep_name|salary|     rank |
+--------+------+----------+
|      CS| 30000|         2|
|   CIVIL| 30000|         2|
+--------+------+----------+  

希望对您有所帮助!