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

时间:2011-05-05 14:38:47

标签: sql oracle join

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

[代码]

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

[/代码]

即。结果是这样的

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

由于

4 个答案:

答案 0 :(得分:11)

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

答案 1 :(得分:2)

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

答案 2 :(得分:0)

以下内容适用于任何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

答案 3 :(得分:0)

试试这个:

用一个作为(选择计数(1)作为counterA,1作为假表从表A), 两个为(选择count(1)作为counterB,1作为来自tableB的虚拟), 三个为(选择count(1)作为counterC,1作为来自tableC的伪), 四为(选择count(1)作为counterD,1作为tableD的伪)

选择one.counterA,two.counterB,three.counterC,four.counterD from one,two,three,four,其中one.dummy = two.dummy和two.dummy = three.dummy和three.dummy = four.dummy; < / b>