2017-10-18 87 views
-3

我想加入3個表格。加入3個或更多表格並總結這些字段

結果是場之一 - 從另一個表這樣的形象SUM,請幫助

Joining table and SUM field

+4

你嘗試過什麼嗎?或者只是想讓我們寫你的代碼並做你的功課? – nacho

+0

我已經使用colasce(),但是我需要在該colasce中添加更多條件,以便可以得到附加的結果,如果可以幫忙的話? – SETYO

+0

這裏的大多數人想要格式化文本,而不是圖像。 (或者,更糟的是,鏈接到圖像。) – jarlh

回答

1

你並不需要加入tblwork,你可以得到從其他2所有必填字段表。

以下查詢應該工作:

select t1.nmstudent, 
      sum(case when t2.idwork = 'w001' then t2.trprice else 0 end) as w001, 
      sum(case when t2.idwork = 'w002' then t2.trprice else 0 end) as w002, 
      sum(case when t2.idwork = 'w003' then t2.trprice else 0 end) as w003, 
      sum(case when t2.idwork = 'w004' then t2.trprice else 0 end) as w004 
    from tblstudent t1 
    inner join tblTrans t2 
    on t1.idstudent = t2.idstudent 
    group by t1.idstudent; 

希望它能幫助!

+0

是的,它的工作原理,但在t1的nmStudent不包含任何值不會出現 – SETYO

+0

因此,該名稱的整行不出現? –

+0

現在不行,謝謝大家 – SETYO