在蜂巢中排名分区

时间:2017-10-26 01:42:34

标签: hiveql

我在表A中有数据,如下所示,有3列属性id,结束日期和密钥,关键字段必须为每个属性ID和结束日期的唯一组合填充唯一值,如下所示

key property id end date
1   7050    12/31/9999
2   7530    12/31/9999
2   7530    12/31/9999
2   7530    12/31/9999
2   7530    12/31/9999
3   7541    12/31/9999
3   7541    12/31/9999
3   7541    12/31/9999
4   7567    12/31/9999
4   7567    12/31/9999

我尝试过做

select rank() over (partition by property_id,effective_end_date) as key,
       property_id,
       end_date 
 from table A

但它将1指定为所有记录的关键字。请帮忙

2 个答案:

答案 0 :(得分:0)

使用以下命令,使用命令:

select rank() over (ORDER by property_id,effective_end_date) as key,
   property_id,
   effective_end_date from table A

答案 1 :(得分:0)

It works just by adding the Order by as below:

select rank() over (partition by property_id order by effective_end_date) as key,
       property_id,
       end_date 
 from table A