有如下表:table
-----------------------------------
Filed0 Filed1
-----------------------------------
a 1
a 2
a 2
b 2
b 3
b 3
------------------------------------
执行:select Filed0,count(*) from table where Filed1>2 group by Filed0
得到结果:
------------------------------------
b 2
------------------------------------
执行:(select Filed0,count(*) from table where Filed1>2 group by Filed0) union (select Filed0,0 from table where Filed0 not in (select Filed0 from table where Filed1>2) group by Filed0) order by Filed0
得到结果:
------------------------------------
a 0
b 2
------------------------------------