使用窗口函数的解决方案:select if(t.client_id=0,'GroupBuy',c.name) as source, count(distinct t.id) as cntfrom (select user_id, client_id, id, count(id) over (partition by user_id) as u_cnt from order_info where product_name in ('C++','Python','Java') and status='completed' ...