2013-06-21 96 views
0

我有3個表流動,我嘗試建立一個查詢來顯示結果。但它只顯示一半。選擇,加入左邊,聯盟。幫我,

Project 
-------------- 
id name 
-------------- 
1  Project 1 
2  Project 2 
3  Project 3 
4  Project 4 
5  Project 5 
6  Project 6 


Pj_rp 
----------------------------- 
id id_pj   id_rp 
----------------------------- 
1  1    1 
2  2    2 
3  1    3 
4  2    4 
5  1    5 
6  3    6 

Report 
-------------- 
id Fee 
-------------- 
1  200 
2  200 
3  400 
4  400 
5  400 
6  400 

我想要得到的結果

**result** 
-------------------- 
Project  SUM(Fee) 
-------------------- 
Project 1  1000 
Project 2  600 
Project 3  400 
Project 4  NULL 
Project 5  NULL 
Project 6  NULL 

與我建立了如下因素查詢,但它錯

SELECT 
    a.name, c.Fee 
from 
    Project a 
     LEFT JOIN 
    Pj_rp b ON (a.id = b.id_pj) 
     LEFT JOIN 
    Report c ON (b.id_rp = c.id) 
GROUP BY a.tongmucdautuduan_usd 

我不知道,誰可以幫我解決這個問題?

謝謝!

+0

你忘了在查詢中使用「SUM(c.Fee)」嗎? –

回答

0
SELECT 
    a.name "Project", sum(c.Fee) 
from 
    Project a 
     LEFT JOIN 
    Pj_rp b ON (a.id = b.id_pj) 
     LEFT JOIN 
    Report c ON (b.id_rp = c.id) 
GROUP BY a.name 
+0

謝謝!我知道了 ! –