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
浙公网安备 33010602011771号