2011-05-05 93 views
4

是否可以將以下查詢作爲一個查詢執行?合併多個oracle查詢以產生一個結果

[代碼]

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

[/代碼]

即得到的結果是這樣的

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

感謝

回答

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

謝謝大家。這工作。 – ziggy 2011-05-05 14:55:03

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 
+1

謝謝。這沒有用。它抱怨在字符'd'缺少關鍵字 – ziggy 2011-05-05 14:55:33

2

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

感謝這個工程,但它垂直顯示結果。 – ziggy 2011-05-05 14:56:04

+0

謝謝,幫助很大! – 2015-05-28 12:28:39

0

試試這個:


一個爲(SELECT COUNT(1)counterA,1從TableA的假人), 兩成(選擇(1)作爲計數器B,1作爲表B中的虛擬計數器, 三個爲(選擇計數(1)作爲計數器C,1作爲表C中的虛擬計數器), 四個爲(選擇計數(1)作爲計數器D,1作爲dumm y 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;

相關問題