更新时间:2022-11-09 22:58:38
您不能将用户定义的变量与LIMIT一起使用.
You cannot use the user defined variables with LIMIT.
MySQL Doc说在大多数情况下,用户变量可能会用到 允许使用表达式.当前不包括上下文 明确需要文字值(例如在LIMIT子句中) SELECT语句或LOAD DATA的IGNORE N LINES子句 声明"
MySQL Doc says "User variables may be used in most contexts where expressions are permitted. This does not currently include contexts that explicitly require a literal value, such as in the LIMIT clause of a SELECT statement, or the IGNORE N LINES clause of a LOAD DATA statement"
But you can achieve similar functionality using 'user defined function' or 'stored procedure' or 'plain SQL by calculating @rowid and using it in the where clause'.