set @rownum =0; Select @rownum: [Email protected]+1 as from table1
: What is the difference between = and =?
- "=", only when set and update are the same as: =, the function of the assignment, the other is equal to the role. In view of this, the use of variables to implement line numbers must be used: =
- ": =", the function of assigning values not only in set and update, but also in select.
If you understand the difference between = and: =, then you understand the phenomenon below.
@num: [Email protected]+1,:= is the function of assignment, so the @num+1 is executed first and then assigned to @num, so the function of line number can be implemented correctly.
@[email protected]+1, at this time = is equal to the role, @num not equal to @num+1, so always return 0, if changed to @[email protected], always return 1. MySQL database, with 1 for true, 0 for false.
MySQL adds serial numbers to query results