第1个回答 2016-07-07
标准的方法是使用UNION联合或者CASE,我认为CASE最好,联合的结果被混淆了,我写一个CASE的例子你试试看:
select
sum(case when `id1`=1 and `check`='b' then 1 else 0 end) cnt1,
sum(case when `id2`=0 and `check`='b' then 1 else 0 end) cnt2,
sum(case when `id3`=1 and `check`='c' then 1 else 0 end) cnt3,
from `table`;
语句输出的结果是这样的,非常直观吧:
cnt1 cnt2 cnt3
2 3 5本回答被提问者和网友采纳