Select 无法按查询对组进行分组 ID

Select not groupable id on a group by query

我正在使用 Mysql 8.0 并尝试执行以下查询,但我没有达到预期的 result.I 需要获得按公司分组的最大值 updated_at。

table:

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 不能在一个组中。

有人可以帮我做一个可以完成这项工作的查询吗?

提前致谢

使用window函数:

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 signatures