mysql5.7实现row_number() over()

示例sql,此sql不能应用于生产,生成rowNumber可以参考。主要是没对country、region等进行group。

select * from
(select 
-- 定义变量 rn, year, month,变量以@开头。满足条件将变量rn+1
 @rn:= case when @year=b.year and @month = b.month then @rn+1 else 1 end as rn, b.sales_volume, b.country,b.region,
 -- 将变量@year等赋值
b.brand,b.kd_cbu,b.prod_mode, @year:=b.year as year, @month:=b.month as month from 
(select * 
from 
(SELECT
	case when country is null or country = '#N/A' then '其他' else country end as country,
  case when region is null or region = '#N/A' then '其他' else region end as region,
	YEAR,month,
	sum(sales_volume) as sales_volume,
	case when brand is null then '其他' else brand end as brand,
	kd_cbu,
	prod_mode
FROM
	omda_data_analysis
	where year = 2021
	GROUP BY year,	month,
	brand) as s_1 ORDER BY s_1.year,s_1.month, s_1.sales_volume desc) b
) a 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值