将两列中的数字值合为一

时间:2018-09-18 05:46:14

标签: oracle sum

我在“借方”列中收到(null),为什么?

SELECT head_name, jv_acc_name, SUM (debit + credit) AS "Debit"
  FROM voucher_detail
  WHERE head_name IN (SELECT name_desc
                        FROM account_heads
                        WHERE acc_name = 'Assets')
GROUP BY head_name, jv_acc_name;

1 个答案:

答案 0 :(得分:1)

尝试检查是否为空并分配0

SELECT head_name, jv_acc_name, SUM (nvl(debit,0) + nvl(credit,0)) AS "Debit"
FROM voucher_detail
WHERE head_name IN (SELECT name_desc
                    FROM account_heads
                    WHERE acc_name = 'Assets')
GROUP BY head_name, jv_acc_name;