mysql 排名实例

select item.*, @rank := @rank + 1 AS personRank
from (
         select detail.entity_id,
                sum(detail.amount) as sumAmount

         from bonus_plan_calculate_detail detail
         where detail.plan_id in (1)
           and detail.entity_type = 0
           and detail.entity_id in (1)
         group by detail.entity_id
         order by sumAmount desc
     ) item,
     (SELECT @rank := 0) r;

结果:

 

posted @ 2023-09-15 18:07  二次元的程序猿  阅读(4)  评论(0编辑  收藏  举报