我正在回答一个遇到此问题的关于 SO 的问题。
为什么我不能MAX()
在 a 内使用LIMIT
?
SELECT *
FROM table
ORDER BY id DESC
LIMIT 0, MAX(id)
或者
SELECT *, MAX(id) AS m
FROM table
ORDER BY id DESC
LIMIT 0, m
两者都给出了类似的语法错误:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MAX(id)' at line 4
通缉查询:
SELECT *
FROM table
ORDER BY id DESC
LIMIT 0, MAX(id)-5