-- 各商品销售数量
with
    t1 as (
        select
            product_id,
            sum(
                case
                    when step = 'select'
                    and pay_method is not null then 1
                    else 0
                end
            ) cnt
        from
            user_client_log
        group by
            product_id
    )
select
    product_name,
    cast(round(price * cnt, 0) as signed) total
from
    t1
    left join product_info p on t1.product_id = p.product_id
order by
    total desc
limit
    2