原始oracle代码
select
row_number() over(partition by a.statis_day,a.app_version order by to_number(a.all_consume/a.cnt) desc) as rn
from
(
select
statis_day
,app_version
,cast(action_consume+gl_consume+draw_consume+engine_consume+ss_consume+sdk_consume as int) as all_consume
,cnt
from 表
)a
Mysql代码
select
@rownum:=@rownum+1
,if(@pdept=a.statis_day and @pver=a.app_version,@rank:=@rank+1,@rank:=1) as rank
,@pver:=a.app_version
,@pdept:=a.statis_day
from
(
select
statis_day
,app_version
,cast(action_consume+gl_consume+draw_consume+engine_consume+ss_consume+sdk_consume as int) as all_consume
,cnt
from 表
ORDER BY cast(action_consume+gl_consume+draw_consume+engine_consume+ss_consume+sdk_consume as int)/cnt desc
)a
,(select @rownum :=0 , @pdept := null,@pver := null ,@rank:=0) c