我目前正在使用 PHP 和 Mysql 中的应用程序,但在操作查询时遇到了一些问题。
这是我的模块表:
+----+-----------+----------+
| Id | Title | Position |
+----+-----------+----------+
| 1 | Module 1 | 1 |
| 2 | Module 2 | 0 |
| 3 | Module 3 | 2 |
+----+-----------+----------+
在我的 php 代码中,我获取了执行查询的模块的 id,例如:$moduleId = 3;
我需要做的是选择具有先前位置的行。
My module id is 3, in this id my position is 2, so I need to select a previous position ... in this case, the Module 1. How can I run this query?
最佳答案
select * from modules where
position < (select position from modules where id=?)
order by position desc limit 1;
哪里?替换为 moduleId
关于php - 选择 mysql 查询中的前一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63379920/