合并多个 oracle 查询以产生一个结果

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5899562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:36:02  来源:igfitidea点击:

Merging multiple oracle queries to produce one result

sqloraclejoin

提问by ziggy

Is it possible to execute the following query as one query?

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

[code]

[代码]

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

[/code]

[/代码]

ie. the result to be something like this

IE。结果是这样的

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

Thanks

谢谢

回答by John

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

回答by xkonnectDeveloper

Yes

是的

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

回答by Lieven Keersmaekers

Following should work with any DBMS.

以下应该适用于任何 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

回答by FerkiC

try this:

尝试这个:

with
one as (select count(1) as counterA, 1 as dummy from tableA), two as (select count(1) as counterB, 1 as dummy from tableB), three as (select count(1) as counterC, 1 as dummy from tableC), four as (select count(1) as counterD, 1 as dummy from tableD)


一个作为(SELECT COUNT(1)作为counterA,1如从表A虚设),两个为(SELECT COUNT(1)作为counterB,1为从tableB的虚设),三个为(SELECT COUNT(1)作为counterC,1为来自 tableC 的虚拟),四个作为(选择 count(1) 作为 counterD,1 作为来自 tableD 的虚拟)

select one.counterA, two.counterB, three.counterC, four.counterD from one, two, three, four where one.dummy = two.dummy and two.dummy = three.dummy and three.dummy = four.dummy;

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