gpt4 book ai didi

mysql - 从 MySQL 表中获取最后更新值

转载 作者:行者123 更新时间:2023-11-29 08:36:11 24 4
gpt4 key购买 nike

我有一个具有以下结构和数据的 mysql 表。我想显示任何 id 上最后插入的记录。

id    lc_counter       lc_timestamp
1 15 2013-03-01 11:54:43
1 13 2013-03-01 11:48:56
10 7 2013-03-01 11:54:43
10 5 2013-03-01 11:48:56
100 5 2013-03-01 11:54:43
100 3 2013-03-01 11:54:43


SELECT inv_id, lc_counter, lc_timestamp
FROM link_counter
group by inv_id
order by inv_id asc, lc_timestamp desc

我想要得到这个结果:

id    lc_counter       lc_timestamp
1 15 2013-03-01 11:54:43
10 7 2013-03-01 11:54:43
100 5 2013-03-01 11:54:43

最佳答案

Select link_counter.lc_counter, MAX(link_counter.lc_timestamp)
from link_counter group by link_counter.id

关于mysql - 从 MySQL 表中获取最后更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15155178/

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