è¿å¤ç¹ççsqlå½±å代ç è´¨éï¼åç»´æ¤ææ¬ï¼ä»¥ä¸ä¸ºä¸¤ç§å°æå·§å¤çæ¹å¼ï¼ä» ä¾åèã
第ä¸ç§ï¼ç¨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 sum3
from 表å
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 fall
FROM `tab_order_info`
WHERE user_id = 11