Chinaunix首页 | 论坛 | 博客
  • 博客访问: 153489
  • 博文数量: 50
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 470
  • 用 户 组: 普通用户
  • 注册时间: 2013-01-10 10:46
文章分类

全部博文(50)

文章存档

2019年(3)

2018年(3)

2017年(2)

2016年(5)

2015年(3)

2014年(1)

2013年(33)

我的朋友

分类: Oracle

2013-11-18 11:42:25

问题
create table abc(A int,B int) 
Select A,count(B) as total from ABC group by A
Select A,count(B) as total1 from ABC where B > 30 group by A
Select A,count(B) as totlal2 from ABC where B > 20 group by A

如何合并这三个查询?
得到一个查询结果:
A,total,total1,total2

解决方案:
Select A,
count(B) as total,
sum(case when B > 30 then 1 else 0 end) as total1,
sum(case when B > 20 then 1 else 0 end) as total2 
from ABC group by A

阅读(823) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~