【问题标题】:Merging multiple oracle queries to produce one result合并多个 oracle 查询以产生一个结果
【发布时间】:2011-08-19 11:09:34
【问题描述】:

是否可以将以下查询作为一个查询执行?

[代码]

select count(*) from tableA;
select count(*) from tableB;
select count(*) from tableC;
select count(*) from tableD;

[/代码]

即。结果是这样的

|TablA|TableB|TableC|TableD|
|50   |300   |30    |9|

谢谢

【问题讨论】:

    标签: sql oracle join


    【解决方案1】:
    select * from
    (select count(*) from tableA),
    (select count(*) from tableB),
    (select count(*) from tableC),
    (select count(*) from tableD);
    

    【讨论】:

      【解决方案2】:

      是的

      select count(*) from tableA;
      union all
      select count(*) from tableB;
      union all
      select count(*) from tableC;
      union all
      select count(*) from tableD; 
      

      【讨论】:

        【解决方案3】:

        以下应该适用于任何 DBMS。

        SELECT *
        FROM   (select count(*) as tableA from tableA) a
               full outer join (select count(*) as tableB from tableB) b
               full outer join (select count(*) as tableC from tableC) c
               full outer join (select count(*) as tableD from tableD) d
        

        【讨论】:

        • 谢谢。这没有用。它抱怨字符“d”上缺少关键字
        【解决方案4】:

        试试这个:


        一个作为(从tableA中选择count(1)作为counterA,1作为dummy), 两个作为(选择计数(1)作为计数器B,1作为表B中的虚拟对象), 三个作为(选择计数(1)作为计数器C,1作为表C中的虚拟对象), 4 as (select count(1) as counterD, 1 as dummy from tableD)

        从一、二、三、四中选择 one.counterA、two.counterB、three.counterC、four.counterD 其中 one.dummy = two.dummy and two.dummy = three.dummy and three.dummy =four.dummy;

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-04-05
          • 1970-01-01
          • 1970-01-01
          • 2022-06-16
          • 2021-09-06
          • 1970-01-01
          • 1970-01-01
          • 2013-07-25
          相关资源
          最近更新 更多