我希望我的 sum 函数返回 '0',如果值不存在,任何人都可以确定以下 SQL 命令是否有问题。我已经改变了合并的顺序,但这并没有什么不同
SqlCommand scGetPostings = new SqlCommand(@"
SELECT
D1.dr,
D1.cr,
D1.asset_no,
(open_bal + dr - cr) AS closing_balance
FROM (SELECT
COALESCE(SUM(dr_amount), 0) AS dr,
COALESCE(SUM(cr_amount), 0) AS cr,
asset_no
FROM posting, sysasset
WHERE posting.asset_no = @AssetNumber
AND period >= asset_open_per
GROUP BY asset_no) AS D1, asset
WHERE D1.asset_no = asset.asset_no", DataAccess.AssetConnection);