数据库
首页 > 数据库> > mysql常用语句

mysql常用语句

作者:互联网

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

标签:语句,常用,incRank,age,curRank,rank,mysql,NULL,select
来源: https://www.cnblogs.com/chengshentao/p/14830139.html