求查询语句,同文件名时间最大的设置状态

Fallenking Fallenking 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
有一组数据

select archiveid, filetime, filename , status
from file_table
order by filename ASC;


+-----------+---------------------+----------+--------+
| id| filetime| filename | status |
+-----------+---------------------+----------+--------+
| 1 | 2014-05-21 01:24:24 | c1.txt | 1 |
| 8 | 2014-05-23 01:24:24 | c1.txt | 1 |
| 10 | 2014-05-21 04:24:26 | c2.txt | 1 |
| 2 | 2014-05-21 01:24:25 | c3.txt | 1 |
| 9 | 2014-05-21 02:24:25 | c3.txt | 1 |
| 3 | 2014-05-21 01:24:26 | c4.txt | 1 |
| 5 | 2014-05-21 03:24:26 | c4.txt | 1 |
| 6 | 2014-05-21 05:24:26 | c4.txt | 1 |
| 7 | 2014-05-22 01:24:26 | c4.txt | 1 |
+-----------+---------------------+----------+--------+

数据库file_table表有4组文件,c1 ~ c4.txt,录入的时间filetime列不一样,每组文件将最大时间的status位设置成3。 求查询语句。

期待结果

+-----------+---------------------+----------+--------+
| id| filetime| filename | status |
+-----------+---------------------+----------+--------+
| 1 | 2014-05-21 01:24:24 | c1.txt | 1 |
| 8 | 2014-05-23 01:24:24 | c1.txt | 3 |
| 10 | 2014-05-21 04:24:26 | c2.txt | 3 |
| 2 | 2014-05-21 01:24:25 | c3.txt | 1 |
| 9 | 2014-05-21 02:24:25 | c3.txt | 3 |
| 3 | 2014-05-21 01:24:26 | c4.txt | 1 |
| 5 | 2014-05-21 03:24:26 | c4.txt | 1 |
| 6 | 2014-05-21 05:24:26 | c4.txt | 1 |
| 7 | 2014-05-22 01:24:26 | c4.txt | 3 |
+-----------+---------------------+----------+--------+
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
Fallenking
MySQL 57,063 成员 56,760 内容