第一种,用case —-when—-方法

    1. select id,
    2. sum(case when type in (1,2) then [count] else 0 end) as sum1,
    3. sum(case when type in (3) then [count] else 0 end) as sum2,
    4. sum(case when type in (4,5) then [count] else 0 end) as sum3
    5. from 表名
    6. group by id

    第二种,if 判断

    1. SELECT SUM( goods_amount ) AS money,
    2. count( * ) AS num,
    3. count(if(pay_status=1,true,null)) AS success,
    4. count(if(pay_status=2,true,null)) AS fall
    5. FROM `tab_order_info`
    6. WHERE user_id = 11