行号函数从Hive中另一个表的最大行号开始

时间:2017-02-21 07:12:43

标签: sql hive hiveql

我有一个查询,其中我要求行号从另一个表的max(row_number)开始。考虑到hive不允许嵌套查询,我该怎么做呢。

所以我的查询是这样的:

Insert Overwrite Table ABC
Select row_number() over (order by Population_Count desc) + select (max(country_id))+1 as country_id,
country_name from ABC_temp;

因此,如果表ABC_temp的country_id结束于26,那么ABC表的row_count()应该从27开始。

2 个答案:

答案 0 :(得分:1)

Insert Overwrite Table ABC

Select      row_number() over (order by Population_Count desc) 
          + max(country_id) over ()

from        ABC_temp
;

答案 1 :(得分:0)

你可以试试这个:

INSERT overwrite TABLE abc
SELECT (temp.m + row_number() over (
                                    ORDER BY population_count DESC)), country_name
FROM abc_temp ,
  (SELECT max(country_id) AS m
   FROM abc_temp) TEMP ;