我的数据已经按最后一列和第三列降序排序。我想在保持原始排序顺序的同时,根据最后一列对数据集进行重复数据消除。所以对于最后的每一列,我想要最后输出的第一行。我需要用Hive来达到这个目的。我的数据是:
10009,12/3/1959,Rodney,Purtle,M,8/28/1986,d007
10010,5/1/1954,Ahishek ,Kumar,M,12/1/1986,d007
10011,1/21/1955,Abhilash,Whatever,M,9/12/1989,d007
10016,5/1/1954,Ross,Hupchuck,M,12/1/1986,d006
10008,1/21/1955,Michael ,Gross,M,9/12/1989,d006
10014,1/21/1955,John ,Talburt,M,9/12/1989,d006
10013,5/1/1954,John,Doe,M,12/1/1986,d006
10015,12/3/1959,Daniel ,Pullen,M,8/28/1986,d006
期望输出:
10009,12/3/1959,Rodney,Purtle,M,8/28/1986,d007
10016,5/1/1954,Ross,Hupchuck,M,12/1/1986,d006
我的当前代码:
select *
from
(select *, row_number() over (partition by last_column order by desc)as r from table_name)s
where r = 1;
我得到的结果是:
10014 1/21/1955 John Talburt M 9/12/1989 d006 1
10010 5/1/1954 Ahishek Kumar M 12/1/1986 d007 1
有谁能帮我一下,并提出我可能做错了什么?
1条答案
按热度按时间2nc8po8w1#
@utsav您可以尝试以下查询:
选择from(select,row\u number()over(partition by last\u column order by third\u column desc)作为r from table\u name),其中r=1 order by last\u column desc;
希望有帮助!