SQL累计支付金额前20%

交易表:user_sales_table
字段:  user_name pay_amount(支付金额)
需求:求累计支付金额前20%

1 select user_name from (
2     select user_name,ntile(5) over(order by tpay desc) nt from (
3         select user_name,sum(pay_amount) tpay from user_sales_table group by user_name
4     ) t1  
5 ) t2 where t2.nt = 1

 

posted on 2025-06-23 12:29  北京的小乔  阅读(10)  评论(0)    收藏  举报