您的位置:首页 > 产品设计 > UI/UE

一个sql语句的思考:select count(*) from table where filedName0=value group by filedName1

2007-06-06 09:02 531 查看
有如下表: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
------------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐