用简单程序替换 MySQL 窗口函数

   日期:2024-12-30    作者:gzkwhzp 移动:http://ljhr2012.riyuangf.com/mobile/quote/81351.html
  A 1 set @i1=null, @i2=0, @i3=0, @d1=null; 2 select curr_month, t1.province, curr_sales, sale_rank,

 

用简单程序替换 MySQL 窗口函数

if(count>1, (sale_rank-1)/(count-1), 0) as `percent_rank`

from (select prev_month, curr_month, province,

@i2:=if(prev_month=curr_month,@i2+1,1) as `row_number`,

@i3:=if(prev_month<>curr_month, 1, if(prev_sales=curr_sales,

@i3, @i2)) as ‘sale_rank’, prev_sales, curr_sales

from (select @i1 as prev_month, @i1:=yearmonth as curr_month,

province, @d1 as prev_sales, @d1:=sales as curr_sales

from (select *

from detail

where yearmonth in (201601,201602)

order by yearmonth, sales desc

) t111

) t11

) t1

join

(select yearmonth, province, count(*) count

from detail

where yearmonth in (201601, 201602)

group by yearmonth

) t2


特别提示:本信息由相关用户自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。


举报收藏 0评论 0
0相关评论
相关最新动态
推荐最新动态
点击排行
{
网站首页  |  关于我们  |  联系方式  |  使用协议  |  隐私政策  |  版权隐私  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  鄂ICP备2020018471号