我将在顶部id(父ID)中加总值,但我对它的分组感到困惑,
SELECT
a.acct_no,
SUM(IF(a.kode = 'D', a.nilai, 0)) AS nilai_debet,
SUM(IF(a.kode = 'K', a.nilai, 0)) AS nilai_kredit
FROM tr2015 a
INNER JOIN acct2015 b ON a.acct_no = b.acct_no
WHERE
a.hps <> '*' AND a.tgl LIKE '2015-01%'
GROUP BY
a.acct_no
ORDER BY
a.acct_no
如何在一个查询中将nilai_debet(子id / 100.01,100.02,...,100.07)的值加总为父ID如100?
答案 0 :(得分:0)
不完全确定,但我觉得您希望SUM()
nilai_debet
的所有值,您可以在外部查询中执行此操作,例如
SELECT SUM(nilai_debet) AS Total_nilai_debet
FROM (
SELECT
a.acct_no,
SUM(IF(a.kode = 'D', a.nilai, 0)) AS nilai_debet,
SUM(IF(a.kode = 'K', a.nilai, 0)) AS nilai_kredit
FROM tr2015 a
INNER JOIN acct2015 b ON a.acct_no = b.acct_no
WHERE
a.hps <> '*' AND a.tgl LIKE '2015-01%'
GROUP BY
a.acct_no
ORDER BY
a.acct_no) XXX;