=
只有在set和update时才是和:=一样,赋值的作用,其它都是等于的作用。鉴于此,用变量实现行号时,必须用:=。
:=
不只在set和update时时赋值的作用,在select也是赋值的作用。
下面是:=和=的在select时作用对比
(1)sql
set @num=0;
SELECT @num:= @num+1 AS rowno, nc as nickname from table_user;
(2)结果
(1)sql
set @num=0;
SELECT @num= @num+1 AS rowno, nc as nickname from table_user;
(2)结果
(1)sql
set @num=0;
SELECT @num= @num AS rowno, nc as nickname from table_user;
(2)结果