我想选择所有时间戳列具有最大值的行。 数据如下:
A B timestamp
john smith 2018
bob dylan 2018
adam levine 2017
bob dylan 2017
结果应为:
A B timestamp
john smith 2018
bob dylan 2018
对于Impala,以下SQL查询有效: SELECT * FROM table WHERE timestamp =(从表中选择Max(timestamp))
但是使用Hive,则不会执行SQL查询。
答案 0 :(得分:4)
请始终包含错误消息。
尝试
SELECT * FROM table WHERE timestamp IN (SELECT Max(timestamp) from table)
答案 1 :(得分:0)
您可以使用等级:
SELECT
D.A
,D.B
,D.timestamp
FROM
(
SELECT
A
,B
,timestamp
,RANK(timestamp) over ( order by timestamp DESC ) as rank_
FROM
TABLE
) D
WHERE
D.rank_=1