1、假设有如下表
date tag
20130101 0
20130101 1
20130102 0
20130101 1
20130103 1
20130101 0
20130103 1要求查询结果如下:
date tag为1的出现次数 tag为0的出现次数
20130101 2 2
20130102 0 1
20130103 2 02、再假设有如下表
date tag
20130101 0
20130101 1
20130102 0
20130101 1
20130103 1
20130101 0
20130103 1
20130101 2
20130102 2
要求查询结果如下:
date tag为1的出现次数 tag不为1的出现次数
20130101 2 3
20130102 0 2
20130103 2 0求SQL实现语句,谢谢!OracleSQL分组查询
date tag
20130101 0
20130101 1
20130102 0
20130101 1
20130103 1
20130101 0
20130103 1要求查询结果如下:
date tag为1的出现次数 tag为0的出现次数
20130101 2 2
20130102 0 1
20130103 2 02、再假设有如下表
date tag
20130101 0
20130101 1
20130102 0
20130101 1
20130103 1
20130101 0
20130103 1
20130101 2
20130102 2
要求查询结果如下:
date tag为1的出现次数 tag不为1的出现次数
20130101 2 3
20130102 0 2
20130103 2 0求SQL实现语句,谢谢!OracleSQL分组查询
解决方案 »
- 求教各位大神,我想要在每天晚上11点执行一个过程,请问下面的语句有什么错误?
- toad 连接数据库 出错:Can't initialize OCI. Error -1
- oracle数据库的增删改查
- 在建立基于函数的索引时报ORA-00406: COMPATIBILITY 参数需要是 8.1.0.0.0 或更大?
- oralce共享服务器模式相关参数设置?
- 函数中如何获得 CURSOR 游标的大小 ???
- 菜鸟请教
- 求助:如何用oracle编写一个返回多条记录的存储过程,并在asp程序中调用
- oracle9i Enterprise Manager Console 找不到数据库
- 关于分布式事务处理急,急,急
- 向各位oracle大牛们求救一个sql问题
- 急求Oracle ERP目前已接收但尚未入库的全部物料的SQL语句
with tb as(
select 20130101 as a,0 as b from dual union all
select 20130101,1 from dual union all
select 20130102,0 from dual union all
select 20130101,1 from dual union all
select 20130103,1 from dual union all
select 20130101,0 from dual union all
select 20130103,1 from dual )
select A,nvl(sum(case when b=1 then 1 else null end),0)
,nvl(sum(case when b=0 then 1 else null end),0) from tb
group by a
order by 1
第一个这么写,第二个照着写就行..
with tb as(
select 20130101 as a,0 as b from dual union all
select 20130101,1 from dual union all
select 20130102,0 from dual union all
select 20130101,1 from dual union all
select 20130103,1 from dual union all
select 20130101,0 from dual union all
select 20130103,1 from dual union all
select 20130101,2 from dual union all
select 20130102,2 from dual
)
select A,nvl(sum(case when b=1 then 1 else null end),0)
,nvl(sum(case when b != 1 then 1 else null end),0) from tb
group by a
order by 1 ;
case when b != 1 or b is null then 1 else null end