0

我有两张数据表,

 Project (ID, NAME, price),
 Expenses (ID, NAME, price, PROJECT_ID,)

我想找到所有项目费用汇总的项目我试过这个查询,但我无法获得所有项目,只有他有费用

SELECT PROJECT.p_id, SUM(EXDE.EXD_AMOUNT) AS T
FROM  PROJECT 
INNER JOIN EXDE
    ON PROJECT.p_id = EXDE.P_NO
GROUP BY  PROJECT.p_id

我将非常感谢任何答案将帮助我找到解决方案

4

2 回答 2

2

内连接只选择两个表中的匹配项。你需要左连接。

SELECT PROJECT.p_id, SUM(EXDE.EXD_AMOUNT) AS T
FROM  PROJECT 
LEFT JOIN EXDE
    ON PROJECT.p_id = EXDE.P_NO
GROUP BY  PROJECT.p_id
于 2012-07-24T15:01:25.130 回答
0

改为使用LEFT JOIN

SELECT   PROJECT.p_id, SUM(EXDE.EXD_AMOUNT) AS T
  FROM   PROJECT 
             LEFT JOIN EXDE
               ON PROJECT.p_id = EXDE.P_NO
GROUP BY  PROJECT.p_id
于 2012-07-24T15:02:24.353 回答