mysql中的运算符
:= 赋值
@ 标识用户变量
@@ 标识用户变量
<=> 做NULL值的关系运算(等同于:IS NULL)
mysql 排名
select id, name, age, @rank := @rank + 1 as rank from rank_test t,(select @rank := 0) tt order by age
age相同,排名相同;排名不跳级
select id, name, age,
if(@preRank = age, @curRank, @curRank := @curRank + 1) as rank,
@preRank := age
from rank_test p,
(select @curRank := 0, @preRank := NULL) r
order by age
age相同,排名相同;排名跳级
select id, name. age
@curRank :=IF(@prevRank = age, @curRank, @incRank) rank,
@incRank := @incRank + 1,
@prevRank := age
from rank_test p,
(select @curRank := 0, @preRank := NULL, @incRank := 1) r
order by age