开发者

Merging multiple oracle queries to produce one result

开发者 https://www.devze.com 2023-03-03 08:07 出处:网络
Is it possible to execute the followi开发者_StackOverflow社区ng query as one query? [code] select count(*) from tableA;

Is it possible to execute the followi开发者_StackOverflow社区ng 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


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


Yes

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


Following should work with any 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


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 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;

0

精彩评论

暂无评论...
验证码 换一张
取 消