`
SELECT TXNID,
TOTAL_AMOUNT,
ACCOUNT_CATEGORY,
DEBIT
FROM ACCOUNTING_BOOK
WHERE TXNID like 'M003%' ;
TXNID:M003 TOTAL_AMT:25 ACCOUNT_CATEGORY:收入借方:null信用:null
TXNID:M003 TOTAL_AMT:25 ACCOUNT_CATEGORY:资产借记:null来源:null
填充借记栏的规则:[如果帐户类别=费用,或者如果帐户类别=与TxnId匹配的相应收入项目的资产,则总金额; 0否则]
想要将此表中的结果验证到借记栏。我该怎么办?
填充信用栏的规则:[总金额,如果帐户类别=收入或如果帐户类别=与TxnId匹配的相应费用项目的资产将返回1; 0否则] 想要将此表中的结果验证到信用列。我该怎么办?
答案 0 :(得分:2)
如果我理解正确的规则:
textureA
编辑:
填充信用栏的规则:[总金额,如果 account-category =收入或if account-category =资产 与TxnId匹配的相应费用项将返回1; 0 否则]
与之前的更新类似:
update accounting_book ab
set debit = case when account_category in ('Expense', 'Asset')
then (select sum(total_amt)
from accounting_book
where account_category = 'Revenue'
and txnid = ab.txnid)
else 0
end
答案 1 :(得分:0)
CASE WHEN A.ACCOUNTCATEGORY IN('Revenue','Asset')
AND EXISTS (SELECT TOTAL_AMOUNT
FROM ACCOUNTING_BOOK
WHERE ACCOUNTCATEGORY='Expense'
AND TXNID=A.TXNID)
THEN A.TOTAL_AMOUNT
ELSE 0
END,
CASE WHEN A.ACCOUNTCATEGORY IN('Expense','Asset')
AND EXISTS (SELECT TOTAL_AMOUNT
FROM ACCOUNTING_BOOK
WHERE ACCOUNTCATEGORY='Revenue'
AND TXNID=A.TXNID)
THEN A.TOTAL_AMOUNT
ELSE 0
end);
END LOOP;
END;
/