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快一倍

相关文章:

  • 2022-02-11
  • 2021-07-11
  • 2022-12-23
  • 2021-08-19
  • 2021-08-07
  • 2022-01-12
  • 2021-07-07
  • 2021-09-14
猜你喜欢
  • 2021-05-06
  • 2021-06-09
  • 2021-07-30
  • 2021-08-04
  • 2022-12-23
  • 2021-11-04
  • 2021-10-04
相关资源
相似解决方案