我正在使用MySQL8.0并试图执行以下查询,但我没有达到预期的结果,我需要获得按公司分组的最大updated_at。
表:
id | updated_at | company
-----------------------------------
5 | 2011-04-14 01:06:06 | 1
3 | 2011-04-14 01:05:41 | 2
7 | 2011-04-15 01:14:14 | 2查询:
select id, MAX(updated_at), company
from signatures
group by company我有一个错误,因为id不能在一个组中。
有人能帮我做一个能做这件事的查询吗?
提前感谢
发布于 2020-08-26 19:52:40
使用窗口函数:
select distinct
first_value(id) over (partition by company order by updated_at desc) id,
max(updated_at) over (partition by company) updated_at,
company
from signatureshttps://stackoverflow.com/questions/63604784
复制相似问题