主 我有3张桌子:
答案 0 :(得分:0)
您可以在相关键上加入表,然后使用条件聚合来转动结果:
select s.nis,
s.nm_lengkap,
sum(case when b.nm_bulan = 'Januari' then p.nominal else 0 end) as Januari,
sum(case when b.nm_bulan = 'Februari' then p.nominal else 0 end) as Februari,
sum(case when b.nm_bulan = 'Maret' then p.nominal else 0 end) as Maret,
...
from tb_siswa s
join tb_spp p on s.id = p.id_siswa
join tb_bulan b on p.id_bulan = b.id
group by s.nis,
s.nm_lengkap;