跪求一条sql统计语句

haitao00244 2009-08-12 02:04:46
假设有一张A表

table A
id name flag
---------------------------
1 'a' true
2 'b' false
3 'c' true
4 'd' true


现在想用一条sql语句实现统计 flag=false的数量和 flag=true的数量

期望结构如下:select count(id) as y,count(id) as n from A .....

在此先谢啦....
...全文
60 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cosio 2009-08-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 inthirties 的回复:]
select sum(decode(flag, 'true', 1, 0)) as y, sum(decode(flag, 'false', 1, 0)) n from A;
[/Quote]

select
sum(case when flag='true' then 1 else 0 end) TRUE个数,
sum(case when flag='false' then 1 else 0 end) FALSE个数
from A;
inthirties 2009-08-12
  • 打赏
  • 举报
回复
select sum(decode(flag, 'true', 1, 0)) as y, sum(decode(flag, 'false', 1, 0)) n from A;
waterfirer 2009-08-12
  • 打赏
  • 举报
回复
问题重了,呵呵
http://topic.csdn.net/u/20090812/14/290b75ad-b187-41b9-89b9-b8fc160c8609.html
fatfoxz 2009-08-12
  • 打赏
  • 举报
回复
这样行吗?
select count(id) as y, flag from A group by flag

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧