Hive SQL为查询结果添加序号

SET mapreduce.job.queuename=xxx;

WITH a AS (
SELECT 'a' col_1, 1 col_2
union all
SELECT 'b' col_1, 2 col_2
union all
SELECT 'c' col_1, 3 col_2
),

b AS (
SELECT 'd' col_1, 1 col_2
union all
SELECT 'e' col_1, 2 col_2
union all
SELECT 'c' col_1, 3 col_2
),

c AS (SELECT * from a UNION SELECT * FROM b)
-- 直接添加序号
-- SELECT row_number() OVER() rnk,* FROM c;
-- 按照col_1排序添加序号
SELECT row_number() OVER(ORDER BY col_1) rnk,* FROM c;

结果如下:

posted @ 2021-05-11 16:11  swordspoet  阅读(1925)  评论(0编辑  收藏  举报