我想做这样的事情:
SET @row_number = 0;
SELECT @row_number := 1 as row_number,* FROM `users`;
我需要的是:
*
+ row_number
上述声明让我误以为*
。
如果我替换所有列名而不是*
,那么它可以正常工作。
像这样:
SET @row_number = 0;
SELECT @row_number := 1 as row_number,Id, Name,UserName,LastName FROM `users`;
但我不想输入所有列名。
有没有解决方案?
答案 0 :(得分:3)
当你说*
时,你必须告诉MySQL你所指的是什么表。
SET @row_number = 0;
SELECT @row_number := 1 as row_number, `users`.* FROM `users`;
或者,您可以切换@row_number
和*
。
SET @row_number = 0;
SELECT *, @row_number := 1 as row_number FROM `users`;
答案 1 :(得分:2)
尝试
SET @row_number = 0;
SELECT @row_number := 1 as row_number,`users`.* FROM `users`;