我在hive下面的表中有列id,名称和时间戳:
根据下面的时间戳,应将输出作为最新记录:
答案 0 :(得分:3)
你不需要为此排名。您的输出描述如下:
select t.*
from t
order by t.transaction_time desc
limit 3;
编辑:
哦,你想要rank()
或dense_rank()
:
select t.*
from (select t.*,
dense_rank() over (order by t.transaction_time desc) as seqnum
from t
) t
where seqnum = 1;
答案 1 :(得分:1)
您可以使用rank
或row_number
:
select *
from (
select t.*,
row_number() over (
partition by name
order by transaction_time desc
) as seq
from your_table t
) t
where seq = 1;