SELECT t.*,
SUM(debet) OVER (PARTITION BY notransaksi) totaldebit,
SUM(kredit) OVER (PARTITION BY notransaksi) totalcredit
FROM (SELECT a.notransaksi,
CASE WHEN right(a.tipetransaksi, 1) = 'D' THEN SUM(a.nilaitransaksi) ELSE 0.00 END
AS totaldebet,
CASE
WHEN right(a.tipetransaksi, 1) = 'K' THEN SUM(b.nilaitransaksi * a.nilaikurs)
ELSE 0.00
END
AS totalkredit,
CASE WHEN right(a.tipetransaksi, 1) = 'D' THEN b.nilaitransaksi ELSE 0.00 END AS debet,
CASE
WHEN right(a.tipetransaksi, 1) = 'K' THEN b.nilaitransaksi * a.nilaikurs
ELSE 0.00
END
AS kredit
FROM thbank2010 as a INNER JOIN tdbank2010 as b ON a.notransaksi = b.notransaksi
WHERE (a.notransaksi = 'BK 015/9966/01/10')
GROUP BY a.notransaksi, a.tipetransaksi, b.nilaitransaksi, a.nilaikurs) as t
|