gpt4 book ai didi

mysql - 如何选择小于值的最新记录

转载 作者:行者123 更新时间:2023-11-29 12:34:26 25 4
gpt4 key购买 nike

我有一个名为conductor的表。我想选择日期小于my_value的最新记录。

+----+-----------+------+
| id | program | date |
+----+-----------+------+
| 1 | program 1 | 1 |
| 2 | program 1 | 3 |
| 3 | program 2 | 3 |
| 4 | program 1 | 5 |
| 5 | program 1 | 7 |
+----+-----------+------+

如果我们认为 my_value 是 4,那么输出将是:

+----+-----------+------+
| id | program | date |
+----+-----------+------+
| 2 | program 1 | 3 |
| 3 | program 2 | 3 |
+----+-----------+------+

如何通过 SQL 选择记录?

最佳答案

SELECT * FROM Conductor
WHERE `date` = (SELECT max(`date`) FROM Conductor
WHERE `date` < myvalue )

关于mysql - 如何选择小于值的最新记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27014573/

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