1
Godykc 2020-04-18 12:23:01 +08:00
关键词 OVER PARTITION BY,然后根据你用的数据库类型自己写着试试,不难的
|
2
gochat 2020-04-18 12:25:57 +08:00
```sql
select * from ttt as a left join( select max(time) as m, bizNo_key from ttt group by bizNo_key ) as b on (a.bizNo_key = b.bizNo_key and a.time = b.m); ``` 多试试 |
3
Yourshell 2020-04-18 12:30:01 +08:00
同是萌新,难道不是 max+group by 吗
|
7
FanGanXS 2020-04-18 13:09:05 +08:00 via iPhone
SELECT
id,context,MAX(time),bizNo,bizNo_Key FROM table_name GOURP BY bizNo_Key |
8
vindac 2020-04-18 16:12:24 +08:00
|
10
MOONYANYI 2020-04-18 17:13:33 +08:00
踏实的就是 left join,简洁的就用窗口函数
|
11
liubian 2020-04-18 20:14:23 +08:00
SELECT * FROM (SELECT id,context,time,bizNo,bizNo_Key FROM table_name ORDER BY time DESC) t GROUP BY bizNo_Key
|
12
forrestgump 2020-04-19 13:00:00 +08:00 via iPhone
@FanGanXS 你这个是认真的吗,group by 还能查询非聚合字段以外的非排序字段?
|
13
ackoly 2020-04-19 19:50:25 +08:00 via iPhone
名称数据库的语法不同,建议提问带上数据库名称和版本
|
14
FanGanXS 2020-04-20 18:23:08 +08:00 via iPhone
@forrestgump Oracle 还真可以
|