RANK Update

2013年12月8日

SELECT @rank:=0;
UPDATE student SET rank=@rank:=@rank+1 ORDER BY rank

//ranking 1,2,3,4,4,6,7,8…
select
(
select
count( B.point) + 1
from
daily_rankers as B
where
B.point > A.point
) as RANK, A.point , A.agency_id ,A.user_id,A.counting_date
from
daily_rankers as A
order by point desc;

//1,2,3,4,4,5,
use app_crm;
select
(
select
count(distinct B.point)
from
daily_rankers as B
where
B.point >= A.point
and
B.agency_id = 19
and
B.counting_date = “2013-09-01″
) as RANK, A.point , A.agency_id ,A.user_id,A.counting_date
from
daily_rankers as A
where agency_id = 19
and
A.counting_date = “2013-09-01″
order by point desc;

Comments are closed.