问题
I have below table in hive with column id, name and time stamp:
On the basis of time stamp below should be the output as latest record:
回答1:
You don't need rank for this. Your output is described by:
select t.*
from t
order by t.transaction_time desc
limit 3;
EDIT:
Oh, you want rank() or dense_rank():
select t.*
from (select t.*,
dense_rank() over (order by t.transaction_time desc) as seqnum
from t
) t
where seqnum = 1;
回答2:
You can use either rank or row_number for this:
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;
来源:https://stackoverflow.com/questions/46306473/how-to-get-the-latest-records-in-hive-using-rank-function