select
t.product_name,
t.sales
from
(select
aa.product_name,
aa.price * aa.cnt as sales,
row_number() over(order by aa.price * aa.cnt desc) as rk
from
(select
b.product_name,
b.price,
count(distinct a.trace_id) as cnt
from
user_client_log a
left join
product_info b on a.product_id = b.product_id
where
a.step = 'select' and a.pay_method is not null
group by
1,2) aa) t
where
t.rk <= 2



京公网安备 11010502036488号