MySQL中實現rank排名查:
https://blog.csdn.net/justry_deng/article/details/80597916
--------每個學院每條記錄的刷卡時間排名(千萬級)------------------
5.7:
SELECT t.academy,@curRank := @curRank + 1 AS rank
FROM (select * from `smartlib_base`.z_gctrl_ctrl_sys tt WHERE tt.enter_time >= '2014-01-01 08:52:26')t, (
SELECT @curRank := 0
) q
ORDER BY t.enter_time;
8.0:
select t.academy_code, rank() over(partition by t.academy_code order by t.operation_time)as rk FROM
(select * from `smartlib_base_2.0.19`.b_gate tt WHERE tt.operation_time >= '2014-01-01 08:52:26')t;
-----------各個學院的刷卡總數排名(百級數據)------------------
5.7:
SELECT t.academy,t.SCORE,@curRank := @curRank + 1 AS rank
FROM ( select count(enter_time) AS SCORE,
academy from z_gctrl_ctrl_sys
GROUP BY academy HAVING
'enter_time' >= '2014-01-01 08:52:26' )t, (
SELECT @curRank := 0
) q
ORDER BY t.SCORE DESC;
8.0:
select t.academy_code, t.`總數`, rank() over( order by t.`總數`)as rk FROM
(select count(operation_time)as `總數`,academy_code from b_gate
GROUP BY academy_code HAVING
'operation_time' >= '2014-01-01 08:52:26' )t;
mysql8.0提供的函數,速度比5.7快一倍