with t as
(select
sum(case when to_char(a.issued_date,'yyyymm')<= '200301' then 1 else 0 end) a,
sum(case when to_char(a.issued_date,'yyyymm')<= '200302' then 1 else 0 end) b,
sum(case when to_char(a.issued_date,'yyyymm')<= '200303' then 1 else 0 end) c,
sum(case when to_char(a.issued_date,'yyyymm')<= '200304' then 1 else 0 end) d,
sum(case when to_char(a.issued_date,'yyyymm')<= '200305' then 1 else 0 end) e
from ecc_bj.ecc_card a
where a.issued_date is not null)
select '200301', t.a from t
union all
select '200302', t.b from t
union all
select '200303', t.c from t
union all
select '200304', t.d from t
union all
select '200305', t.e from t
(select
sum(case when to_char(a.issued_date,'yyyymm')<= '200301' then 1 else 0 end) a,
sum(case when to_char(a.issued_date,'yyyymm')<= '200302' then 1 else 0 end) b,
sum(case when to_char(a.issued_date,'yyyymm')<= '200303' then 1 else 0 end) c,
sum(case when to_char(a.issued_date,'yyyymm')<= '200304' then 1 else 0 end) d,
sum(case when to_char(a.issued_date,'yyyymm')<= '200305' then 1 else 0 end) e
from ecc_bj.ecc_card a
where a.issued_date is not null)
select '200301', t.a from t
union all
select '200302', t.b from t
union all
select '200303', t.c from t
union all
select '200304', t.d from t
union all
select '200305', t.e from t
解决方案 »
- Oracle 分组排序问题
- pl/sql中使用insert into select复制一个表,并且主键使用序列生成的值?
- 急求sql语句优化
- 请问如何得到Oracle SQLException的errorCode, 用SQLException.getErrorcode() 总是返回0
- 关于ORACLE的几个基本概念问题
- 我有一些sql脚本,怎样才能放到我的oracle sever运行起来呢
- 如何,从DMP全导出文件中恢复数据.
- 100分请教:两个表之间的行连接问题
- 初学求教,Oracle中如何从一个*.dmp文件中恢复一个表的结构?
- 请教一个orcale触发器中关于时间相减问题?(up有分)
- 大家好~用什么样得SQL语句能够查询出数据库中得数据库都是什么呢?
- [请教]sqlldr导入数据引起的主键索引失效问题?
from ( select * from ecc_bj.ecc_card where issued_date is not null ) ds,
( select distinct to_char(issue_date, 'YYYYMM') issue_month
from ecc_bj.ecc_card where issued_date is not null ) m
where to_char(ds.issue_date, 'YYYYMM') <= m.issue_month
group by m.issue_month
select issue_month, counts
from
( select m.issue_month, count(ds.issue_date) counts
from ( select * from ecc_bj.ecc_card where issued_date is not null ) ds,
( select distinct to_char(issue_date, 'YYYYMM') issue_month
from ecc_bj.ecc_card where issued_date is not null ) m
where to_char(ds.issue_date, 'YYYYMM') <= m.issue_month
group by m.issue_month ) t
where t.issue_month >= '200301'
and t.issue_month <= '200305'
是把括号里的查询结果作为一个表,别名为t