加入3个或更多表格并总结这些字段

问题描述:

我想加入3个表格。加入3个或更多表格并总结这些字段

结果是场之一 - 从另一个表这样的形象SUM,请帮助

Joining table and SUM field

+4

你尝试过什么吗?或者只是想让我们写你的代码并做你的功课? – nacho

+0

我已经使用colasce(),但是我需要在该colasce中添加更多条件,以便可以得到附加的结果,如果可以帮忙的话? – SETYO

+0

这里的大多数人想要格式化文本,而不是图像。 (或者,更糟的是,链接到图像。) – jarlh

你并不需要加入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