select case when pay_method = '' then 'error' else pay_method end as pay_method, count(*) as cnt from user_client_log u join product_info p on u.product_id = p.product_id where product_name = 'anta' and step = 'select' and pay_method is not null group by pay_method order by cnt desc;
首先合并两个表,再选出product_name = 'anta' and step = 'select' and pay_method is not null的行,再按照支付方式分类,并计算次数,对没有记录支付方式的用case when 显示error。