如何根据订购的条件执行一个发出编号列的MySQL语句?例如,通过使用变量,我已经能够生成这样的列,但编号过程在订购之前发生,因此结果看起来是......无序的
答案 0 :(得分:0)
尝试添加一个计数器:
SELECT t.field, t.fieldbis
@curRow := @curRow + 1 AS row_number
FROM table l
JOIN (SELECT @curRow := 0) r
WHERE t.field > 50
ORDER BY t.field2
请参阅With MySQL, how can I generate a column containing the record index in a table?