当我运行我的程序时,该数字的结果改为合并一个数字,并使该数字成许多结果。

SELECT pengiriman_supply.po_nomor
    , data_supplier.nama_supplier
    , data_barang.nama_barang,
((sum(pengiriman_supply.jumlah))-(ifnull(masuk.terima,0))) as total
FROM pengiriman_supply INNER JOIN data_supplier ON pengiriman_supply.idsupplier = data_supplier.id_supplier
INNER JOIN data_barang ON pengiriman_supply.idbarang = data_barang.idbarang
left JOIN masuk on masuk.refrence = pengiriman_supply.po_nomor
where pengiriman_supply.tanggal between date_sub(curdate(), interval 120 day) and curdate()
group by pengiriman_supply.po_nomor
ORDER BY pengiriman_supply.po_nomor desc;


结果是这个
enter image description here

最佳答案

似乎您正在尝试获取每个sum()po number。让我们将其放在subquery中,然后再次join您要显示信息的那些表。

select t.po_nomor
    , p.nama_supplier
    , p1.nama_barangfrom
    , t.total
from
    (select t1.po_nomor
            , (sum(t1.jumlah)-coalesce(t4.terima,0)) as total
        from pengiriman_supply t1
        inner join data_supplier t2 on t1.idsupplier = t2.id_supplier
        inner join data_barang t3 on t1.idbarang = t3.idbarang
        left join masuk t4 on t4.refrence = t1.po_nomor
        where t1.tanggal between date_sub(curdate(), interval 120 day) and curdate()
        group by t1.po_nomor) t
inner join pengiriman_supply s on s.po_nomor = t.po_nomor
inner join data_supplier p on s.idsupplier = p.id_supplier
inner join data_barang p1 on t.idbarang = p1.idbarang
order by t.po_nomor desc;

关于mysql - 我怎么加在SQL上,所以它不会加倍,因为分组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58811251/

10-11 01:57