gpt4 book ai didi

mysql - 从给定出现的mysql开始计算行

转载 作者:行者123 更新时间:2023-11-30 21:28:23 25 4
gpt4 key购买 nike

我有这张 table

+----+-----+-------------+
| id | num | timestamp |
+------------------------+
| 1 | 0 | 1565780410 |
| 2 | 1 | 1565780710 |
| 3 | 2 | 1565780510 |
| 4 | 0 | 1565780310 |
| 5 | 1 | 1565780810 |
+------------------------+

我想检索从值为 0 的最后一列“num”开始到现在按时间戳排序的行数。在这种情况下,结果将为 2(从第 4 行到第 5 行)。所以输出将是:

+-----+
| num |
+-----+
| 2 |
+-----+

有办法吗?非常感谢你,对不起我的英语不好。

最佳答案

你可以试试这个。您只需要找到具有 0 值的列的 Max id。然后剩下的行就是你的结果。

计数

select count(1) as count from table where id >= (select Max(id) from table where num = 0 )

对于行

select * from table where id >= (select Max(id) from table where num = 0 )

关于mysql - 从给定出现的mysql开始计算行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57622271/

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