mysql分组排名

关联一个 ( SELECT @id := 0 ) idVal,用逗号就行,或者用join 且要嵌套多层

 select t2.* from (
             select
              ( @id := @id + 1 ) AS id,
              t.* from (
                    SELECT
                        COUNT( act.visit_no ) rankCount,
                        act.nameFROM
                        activity_clock_type act                      
WHERE act.activity_no = #{activityNo} GROUP BY act.staff_no ORDER BY rankCount DESC , act.create_time asc ) t , ( SELECT @id := 0 ) idVal ) t2

 

posted @ 2020-10-12 14:15  关键步就几步  阅读(308)  评论(0编辑  收藏  举报