select product_name,sale from ( select p.product_id,price*num as sale,product_name, rank()over(order by price*num desc) as rank_num from product_info p join ( select product_id,count(1) as num from (select product_id,trace_id from ( select trace_id,product_id,pay_method from user_client_log where pay_method != '' ) as u group by product_id,trace_id) as t1 group by product_id) as t2 on p.product_id = t2.product_id) as t3 order by rank_num limit 2

京公网安备 11010502036488号