SQL语句一:
select glaccountid,debit,credit
from transactionentries
where glaccountid in (15376);上面的语句返回下面的输出:
+------------------------------+
| glaccountid | debit | credit |
+------------------------------+
| 15376 | 1584 | null |
+------------------------------+
| 15376 | null | 1400 |
+------------------------------+SQL语句二:
select glaccountid,debit,credit
from transactionentries
where glaccountid in (15374);Above语句返回以下结果:
+------------------------------+
| glaccountid | debit | credit |
+------------------------------+
| 15374 | null | 1584 |
+------------------------------+
| 15374 | 14000 | null |
+------------------------------+我正在尝试编写一个查询,通过忽略具有空值的列,返回15376的借记值与15374的贷记值不相等的事务条目,反之亦然。
我已经尝试过了:
SELECT cpo.glaccountid cpo,cpo.debit,cpo.credit,ba.glaccountid branch, ba.debit,ba.credit
FROM transactionentries cpo
INNER JOIN transactionentries ba
ON cpo.transactionid = ba.transactionid
WHERE cpo.glaccountid = 15374
AND ba.glaccountid = 15376
AND (cpo.debit <> ba.credit OR ba.debit <> cpo.credit);预期输出:
+------------------------------+
| glaccountid | debit | credit |
+------------------------------+
| 15374 | 14000 | null |
+------------------------------+
| 15376 | null | 1400 |
+------------------------------+发布于 2019-07-29 21:31:48
您不能将null当作一个值进行比较,因为null在Oracle中的含义是“无信息”,而不是一个值。关于这一点,你可能会找到很多好的答案。
关于您的查询,如果您想只考虑具有两个not null值的记录,这可以是编辑where条件的一种不言而喻的方法:
(
(cpo.debit <> ba.credit and cpo.debit is not null and ba.credit is not null)
or
(ba.debit <> cpo.credit and ba.debit is not null and cpo.credit is not null)
)你可以用不同的方式编辑它;这是readableI能想到的最多的。
https://stackoverflow.com/questions/57254638
复制相似问题