Hive / SQL查询每个键的前n个值

时间:2018-06-21 17:51:36

标签: sql hive hql hiveql

我想要每个键的前2个值。结果如下:

enter image description here

配置单元查询应该是什么。

1 个答案:

答案 0 :(得分:0)

您可以将window function()关闭时使用OVER

select col1,col2 from (SELECT col1,
col2, 
ROW_NUMBER() OVER (PARTITION BY col1 ORDER BY col2 DESC) AS row_num
FROM data)f
WHERE f.row_num < 3
order by col1,col2