Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这意味着什么?我无法理解语法。
SELECT if(@s, @s:=@s+1, @s:=1) as rownum, user_id, operation FROM users_list
这会在第一条记录处初始化一个变量@s,并为接下来的每一行添加。这是一种排名机制,用于动态获取选择中每条记录的行号。11
@s
1
结果可能如下所示
rownum | user_id | operation 1 | 1 | 'delete' 2 | 4 | 'add' 3 | 2 | 'create' 4 | 2 | 'delete'