可以
如下形式:
select
(select ...),
(select ...),
(select ...)
from dual;
如下形式:
select
(select ...),
(select ...),
(select ...)
from dual;
解决方案 »
- 谁能帮我优化一下这个语句
- oracle建表问题。
- IMPDP network_link 报ora-39149错误
- 如何删除oracle中的数据库
- JOB调用存储过程如何实现存储过程的并发执行?
- 关于oracle读写os文件!请帮忙!
- 紧急求助!!由于误操作使用了drop table 使oracle8i中的数据丢失无数据库倍份,是否有办法恢复?
- Oracle数据库运行一段时间后就无法连接,提示Ora-12547:TNS丢失联系
- oracle中执行一个sql文件的语句怎么写?
- oracle报表数据源连接是怎样连接的?
- 求SQL SEVER与ORACLE都精通高手,急
- ★★在dbastudio中能查看到结果,但是为什么在SqlPlus中在同一个表中不能查询到结果,提示信息是表或试图不存在★★
---------- ---------- ---------- ----------
1 333 333 01-7月 -02
1 333 333 01-5月 -02
1 333 333 20-8月 -02
62 sdfds 6 01-7月 -02
63 sdfds 6 01-7月 -02
1 333 333 01-7月 -02
83 sdfds 6 01-7月 -02
91 sdfds 6 01-7月 -02
92 sdfds 6 01-7月 -02
93 sdfds 6 22-8月 -02
94 sdfds 6 02-8月 -02 ID ZYZ1 P1 DOCTIME
---------- ---------- ---------- ----------
2 01-9月 -02
1 333 333 01-9月 -02
3 01-9月 -02
4 temp 5 01-1月 -02
5 字符集 01-7月 -02
16 sdfdsfsdf 01-7月 -02
17 sdfdsfsd43 01-7月 -02
43f
18 rows selected.SQL> select * from test3; ID DOCTIME P1 NEWZYZ
---------- ---------- ---------- ----------
25 01-7月 -01 sdfsdfdsf
26 01-7月 -01 erwd
41 01-7月 -01 字符集
6 01-7月 -01 zyz
22 01-7月 -01 dfSQL> select id c,sum(decode(tablename,'test1',1,0)) cnt1, sum(decode(tablename,'
test1',decode(p1,333,1,0),0)) cnt2,sum(decode(tablename,'test3',1,0)) cnt3, sum(
decode(tablename,'test3',decode(p1,null,1,0),0)) cnt4 from
2 (select id,p1,'test1' tablename from test1 where doctime=to_date('2002-07
-01','yyyy-mm-dd') union all select id,p1,'test3' tablename from test3 where doc
time=to_date('2001-07-01','yyyy-mm-dd'))
3 group by id; C CNT1 CNT2 CNT3 CNT4
---------- ---------- ---------- ---------- ----------
1 2 2 0 0
5 1 0 0 0
6 0 0 1 1
16 1 0 0 0
17 1 0 0 0
22 0 0 1 1
25 0 0 1 1
26 0 0 1 1
41 0 0 1 1
62 1 0 0 0
63 1 0 0 0 C CNT1 CNT2 CNT3 CNT4
---------- ---------- ---------- ---------- ----------
83 1 0 0 0
91 1 0 0 0
92 1 0 0 014 rows selected.你的sql照着改一下就可以了。
select coll,sum(decode(tablename,'table1',1,0)) cnt1, sum(decode(tablename,'table1',decode(col2,1,1,0),0)) cnt2,sum(decode(tablename,'table2',1,0)) cnt3, sum(decode(tablename,'table2',decode(col2,1,1,0),0)) cnt4 from
(select coll,col2,'table1' tablename from table1 where sendtime between '日期1' and '日期2' union all select coll,col2,'table2' tablename from table2 where sendtime between '日期1' and '日期2')
group by coll
你是想要这样吗?
select A.col1,A.cnt1,B.cnt2,C.cnt3,D.cnt4 From(select col1,count(*) cnt1 from table1 where sendtime between '日期1' and '日期2' group by col1) A,(select col1,count(*) cnt2 from table1 where col2=1 and sendtime between '日期1' and '日期2' group by col1)B,(select col1,count(*) cnt3 from table2 sendtime where sendtime between '日期1' and '日期2' group by col1)C,(select col1,count(*) cnt4 from table2 where col2=1 and sendtime between '日期1' and '日期2' group by col1)Dwhere A.col1=B.col1 and A.col1=C.col1 and A.col1=D.col1