第一种,用case —-when—-方法
select id,sum(case when type in (1,2) then [count] else 0 end) as sum1,sum(case when type in (3) then [count] else 0 end) as sum2,sum(case when type in (4,5) then [count] else 0 end) as sum3from 表名group by id
第二种,if 判断
SELECT SUM( goods_amount ) AS money,count( * ) AS num,count(if(pay_status=1,true,null)) AS success,count(if(pay_status=2,true,null)) AS fallFROM `tab_order_info`WHERE user_id = 11
