mysql分组后实现排序,不用临时变量实现
网上找了一大堆全都是要使用临时变量实现,但是觉得好麻烦,最后在同事的协助下终于搞定啦。
排序方式为 1 2 2 4 (如果要实现 1 2 2 3 这种把 count(s.tday_mng_ast) + 1 改为 count(DISTINCT s.tday_mng_ast) + 1 即可),
CM_PST_ID为岗位id,要实现该岗位下按tday_mng_ast这个数量进行排名
SELECT
t.`CM_USR_ID`,
t.`CM_USR_NM`,
CM_PST_ID,
tday_mng_ast,
(select
count(s.tday_mng_ast) + 1
from
app_bs06_r_cm_mng_ast_chg_day_sr s
where s.tday_mng_ast > t.tday_mng_ast
and s.ZZDW_STAT_DT = '2020-01-08'
and s.AST_TYP_CD = 'TMKV'
and s.CM_PST_ID = t.CM_PST_ID) rank
from
APP_BS06_R_CM_MNG_AST_CHG_DAY_SR t
where t.`AST_TYP_CD` = 'TMKV' and t.ZZDW_STAT_DT = '2020-01-08'
and t.`CM_Brn_ORG_ID`='257758'
执行完如图所示 :