2016-10-17 85 views
0

我認爲這是一個非常簡單的問題,但我沒有找到有用的東西。連續重組結果

我做3點的選擇,看起來像這樣:

SELECT count(*) as nbTable1 
FROM table1, joinTable 
WHERE table1.A = joinTable.A; 

SELECT count(*) as nbTable2 
FROM table2, joinTable 
WHERE table1.A = joinTable.A; 

SELECT count(*) as nbTable3 
FROM table3, joinTable 
WHERE table1.A = joinTable.A; 

我想組的結果在一排:

nbTable1 | nbTable2 | nbTable3 | 
-------------------------------- 
     12 |  8 |  15 | 

我試圖UNION的結果,但我得到

nbTable1 | 
---------- 
     12 | 
     8 | 
     15 | 

由於我在每個請求中使用了joinTable,因此我無法在單個select中完成...可以幫助我嗎? :)

回答

0
SELECT 
     (SELECT count(*) 
     FROM table1, joinTable 
     WHERE table1.A = joinTable.A) nbTable1, 
     (SELECT count(*) 
     FROM table2, joinTable 
     WHERE table2.A = joinTable.A) nbTable2, 
     (SELECT count(*) 
     FROM table3, joinTable 
     WHERE table3.A = joinTable.A) nbTable3 
FROM DUAL; 
+0

謝謝,它的工作原理。 count(*)後我刪除了'as nbTable1',因爲它沒有帶來任何東西:) – Mistalis