gpt4 book ai didi

mysql - 从MySQL数据中获取最新5行日期

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

只有5个标题;那是我的 table :

ID   Title   Time
1 DA-UB 2017-05-14 15:02:03
2 UB-SA 2017-05-14 15:03:03
3 ER-UB 2017-05-14 15:04:03
4 DA-UB 2017-05-14 15:05:03
5 UB-sa 2017-05-14 15:06:03
6 ER-UB 2017-05-14 15:07:03
7 OR-SA 2017-05-14 15:10:03
8 ER-DA 2017-05-14 15:11:03

我想看看这个(最后添加的 5 行)

4    DA-UB   2017-05-14 15:05:03
5 UB-sa 2017-05-14 15:06:03
6 ER-UB 2017-05-14 15:07:03
7 OR-SA 2017-05-14 15:10:03
8 ER-DA 2017-05-14 15:11:03

最佳答案

使用LIMIT:

select *
from your_table
order by time desc
limit 5

编辑:

根据下面评论中的最新更新,您可以使用有限的相关查询来获取每个标题的最新行,然后将结果限制为 5 行。

select *
from your_table t1
where id = (
select id
from your_table t2
where t1.title = t2.title
order by time desc
limit 1
)
order by time desc
limit 5;

关于mysql - 从MySQL数据中获取最新5行日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43985026/

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