可以
如下形式:
select
(select ...),
(select ...),
(select ...)
from dual;

解决方案 »

  1.   

    SQL> select * from test1;        ID ZYZ1               P1 DOCTIME
    ---------- ---------- ---------- ----------
             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照着改一下就可以了。
      

  2.   

    你的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
      

  3.   

    把视图的定义合到sql中不就行了?
      

  4.   

    什么是“把视图的定义合到sql中”,视图定义不就是SQL语句吗?谢谢
      

  5.   

    不太明白你的意思:“生成如下形式的报表:col1,cnt1,cnt2,cnt3,cnt4”
    你是想要这样吗?
    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