gpt4 book ai didi

Hive 查询获取表中插入的最后一条记录

转载 作者:行者123 更新时间:2023-12-02 05:42:52 27 4
gpt4 key购买 nike

 a                date             time         b
35573407 20170412 140930 310260453908912
35573407 20170412 140930 310260453908912
35573407 20170412 141054 310260453908912
35573407 20170412 025339 310260453908912
35573407 20170412 072918 310260453908912
35573407 20170412 091105 310260453908912
35573422 20170412 193605 310260453908912
35573407 20170412 121105 310260453908912
35573407 20170412 032439 310260453908912
35573407 20170412 032605 310260453908912

我正在尝试找出一个 hive 查询,该查询获取带有 b 的表中插入的最后一条记录。需要将记录按时间列排序并获取最后一条记录。假设上面的记录

35573422  20170412  193605  310260453908912

是最后一条记录。

最佳答案

select  a,date,time,b

from (select *
,row_number() over
(
partition by b
order by date desc
,time desc
) as rn

from mytable
) t

where t.rn = 1
<小时/>
+----------+----------+--------+-----------------+
| a | date | time | b |
+----------+----------+--------+-----------------+
| 35573422 | 20170412 | 193605 | 310260453908912 |
+----------+----------+--------+-----------------+

关于Hive 查询获取表中插入的最后一条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43417629/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com