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

时间:2021-02-04 00:48:20

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

即。结果是这样的

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

Thanks

谢谢

4 个解决方案

#1


11  

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

#2


2  

Yes

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

#3


0  

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

#4


0  

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)

用一个作为(选择count(1)作为counterA,1作为来自tableA的伪),两个作为(选择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;

#1


11  

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

#2


2  

Yes

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

#3


0  

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

#4


0  

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)

用一个作为(选择count(1)作为counterA,1作为来自tableA的伪),两个作为(选择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;