maxcompute使用窗口函数,对于某个字段进行排名

https://help.aliyun.com/document_detail/34994.html?spm=a2c4e.11153940.0.0.55953073yYjdBA

SELECT *
from
(
select t.userid,t.totalamount, PERCENT_RANK() OVER(PARTITION BY t.userid ORDER BY t.totalamount DESC) as amount_rank
from ticket_ods t where t.pt=20190907
) a
where amount_rank>0.1 and amount_rank<0.9
 
【注意】:窗口函数只能用在子查询中,就是where rank>0.1这个,要在外面,不能在子查询里面使用
 
 

select sum(p.kedanjia)/count(*) as industry_per_ticket, c.tag from
(select i.userid, sum(i.totalamount)/count(*) as kedanjia
from
(
SELECT *
from
(
select t.userid,t.totalamount, PERCENT_RANK() OVER(PARTITION BY t.userid ORDER BY t.totalamount DESC) as amount_rank
from ticket_ods t where t.pt=20190907
) a
where amount_rank>0.1 and amount_rank<0.9
) i

group by i.userid) p

inner join company_classification_temp c
on p.userid = c.userid
GROUP by c.tag
 
查找每个userid下面,totalamount排名在0.1-0.9之间的单子

转载于:https://www.cnblogs.com/yjybupt/p/11512215.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值