我想加入3个表。
结果是其中一个字段 - 来自其他表的SUM,如此图片,请帮助
答案 0 :(得分: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;
希望它有所帮助!