select ranks from (select id,name,@rank:=@rank+1 as ranks from user u, (select @rank:=0) ran order by u.age) r where id=xxx
select ranks from (select user_id, rank() over(order by price desc) as ranks from bid ) res where user_id=xxx
SELECT a.stu_id,a.point,
IF( @className = a.class_name,@rank := @rank + 1,@rank :=1 ) AS rank,
(@className := a.class_name) class_name
FROM TMP_A a, ( select @rank :=0,@className := NULL ) b
ORDER BY a.class_name, a.point DESC ;
排序
SELECT a.stu_id,a.point,
@rank:=case when @className = a.class_name then @rank := @rank + 1
when @className := a.class_name then @rank :=1
when a.class_name =0 then @rank :=1 else ‘’ end rank,
@className := a.class_name
FROM TMP_A a, ( select @rank :=0,@className := NULL ) b
ORDER BY a.class_name, a.point DESC ;
评论 (0)