Update tabel header dari tabel detail
UPDATE a
SET a.kolom_header = b.HRG
FROM tabel_header a
INNER JOIN
(
SELECT kode_id, SUM(trans_detail) AS HRG
FROM tabel_detail
GROUP BY kode_id
) b ON a.kode_id = b.kode_id
[WHERE (kondisi)]
Contoh :
update a
set a.totalqty = b.ttlqty
from jual_header a
inner join
(
select id, sum(trans_qty) as ttlqty
from jual_detail group by id
) b on a.id = b.id where a.tgl between '2016-01-01' and '2016-01-05'
Tidak ada komentar:
Posting Komentar