显示输入的最后数据

时间:2017-06-02 01:43:35

标签: sql select group-by sql-order-by

我有8个表,每个表都有一个' id_siswa'关系。我同时将数据添加到8个表中,但并不总是全部填充, 示例如下图2:

enter image description here

enter image description here

我想显示我最后输入的数据,如何掌握, 这是我的sql仍然是错误的......

select tb_siswa.NIS, tb_siswa.nm_lengkap, tb_siswa.sekolah, tb_pernyataan.kelas, tb_bulan.nm_bulan, tb_angsuran_spp.nominal_spp, DATE_FORMAT(tb_angsuran_spp.created_at, "%d/%m/%Y") as created_at, tb_angsuran_spp.id, tb_angsuran_seragam.nominal_seragam, tb_angsuran_bops.nominal_bops, tb_angsuran_daycare.nominal_daycare, tb_angsuran_extrapilihan.nominal_extrapilihan, tb_angsuran_extrawajib.nominal_extrawajib, tb_angsuran_iuran.nominal_iuran, tb_angsuran_parenting.nominal_parenting, tb_angsuran_wakaf.nominal_wakaf, tb_tabungan.masuk, 
            SUM(COALESCE(tb_angsuran_spp.nominal_spp,0) + COALESCE(tb_angsuran_seragam.nominal_seragam,0) + COALESCE(tb_angsuran_daycare.nominal_daycare,0) + COALESCE(tb_angsuran_extrapilihan.nominal_extrapilihan,0) + COALESCE(tb_angsuran_extrawajib.nominal_extrawajib,0) + COALESCE(tb_angsuran_parenting.nominal_parenting,0) + COALESCE(tb_angsuran_bops.nominal_bops,0) + COALESCE(tb_angsuran_bops.nominal_bops,0) + COALESCE(tb_angsuran_iuran.nominal_iuran,0) + COALESCE(tb_tabungan.masuk,0)) as total
            from tb_siswa
            left join tb_angsuran_spp on tb_siswa.id = tb_angsuran_spp.id_siswa
            left join tb_angsuran_bops on tb_angsuran_spp.id = tb_angsuran_bops.id
            left join tb_angsuran_seragam on tb_angsuran_spp.id = tb_angsuran_seragam.id
            left join tb_angsuran_daycare on tb_angsuran_spp.id = tb_angsuran_daycare.id
            left join tb_angsuran_extrapilihan on tb_angsuran_spp.id = tb_angsuran_extrapilihan.id
            left join tb_angsuran_extrawajib on tb_angsuran_spp.id = tb_angsuran_extrawajib.id
            left join tb_angsuran_parenting on tb_angsuran_spp.id = tb_angsuran_parenting.id
            left join tb_angsuran_wakaf on tb_angsuran_spp.id = tb_angsuran_wakaf.id
            left join tb_angsuran_iuran on tb_angsuran_spp.id = tb_angsuran_iuran.id
            left join tb_tabungan on tb_angsuran_spp.id = tb_tabungan.id
            left join tb_bulan on tb_angsuran_spp.id_bulan = tb_bulan.id
            left join tb_pernyataan on tb_siswa.id = tb_pernyataan.id_siswa
            group by tb_siswa.id, tb_angsuran_spp.id
            order by tb_angsuran_spp.created_at DESC limit 1

谢谢

0 个答案:

没有答案