gpt4 book ai didi

mysql - 如何根据日期进行记录

转载 作者:行者123 更新时间:2023-11-29 06:48:10 25 4
gpt4 key购买 nike

在我的数据表中,有一个名为 special_id 的列,其中包含不唯一的值。

例如:

+-----+-----+------------+-------------------------+
| ... | ... | special_id | add_date |
+-----+-----+------------+-------------------------+
| ... | ... | 1111 | 2018-02-02 09:42:11.993 |
| ... | ... | 2222 | 2018-02-01 09:42:11.993 |
| ... | ... | 1111 | 2018-01-31 09:42:11.993 |
| ... | ... | 3333 | 2018-01-02 09:42:11.993 |
| ... | ... | 4444 | 2018-01-22 09:42:11.993 |
+-----+-----+------------+-------------------------+

我想知道我是否可以(使用 SQL)SELECT 基于 具有匹配 special_id最新记录添加_日期列?

最佳答案

你是这个意思吗?

select t.*
from t
where t.add_date = (select max(t2.add_date) from t t2 where t2.special_id = t.special_id);

关于mysql - 如何根据日期进行记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48588080/

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