跪求一条sql统计语句

haitao00244 2009-08-12 02:36:33
假设有一张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 .....
...全文
52 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
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
  • 打赏
  • 举报
回复
select sum(decode(flag,'true',1,0)) as y, sum(decode(flag,'flase',1,0)) as n from A
超叔csdn 2009-08-12
  • 打赏
  • 举报
回复
select count(case when flag='false' then id end ) as y,count(case when flag='true' then id end ) as n from A
超叔csdn 2009-08-12
  • 打赏
  • 举报
回复
select count(case when flag='false' then id end ) as y,count(case when flag='true' then id end ) as n from A
zcs_1 2009-08-12
  • 打赏
  • 举报
回复
select flag, count(*) from a group by flag
zcs_1 2009-08-12
  • 打赏
  • 举报
回复
select flag, count(*) from a group by flag

17,082

社区成员

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

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