答案 0 :(得分:1)
由于你已经在这里用mysql标记了这个问题,你怎么做呢
select
t1.id,
t1.user_name,
sum(case when t2.shop_status = 'returned' then 1 else 0 end) as `num_of_return`,
sum(case when t2.shop_status = 'shopped' then 1 else 0 end) as `num_of_shopped`,
sum(case when t2.shop_status = 'cancelled' then 1 else 0 end) as `num_of_cancelled`
from table1 t1
left join table2 t2 on t2.user_id = t1.id
group by t1.id