oracle - 如何编写“选择查询”以仅使用一张表查找一个帐户的借方和另一个帐户的贷方之间的差异?
问题描述
sql语句:
SELECT debit,credit FROM transactionentries where glaccountid = 15374;
SELECT debit,credit FROM transactionentries where glaccountid = 15376;
提示:debit
此 glaccountid 的15374
必须等于credit
其他 glaccountid 的 ,15376
反之亦然。
我想要得到的是返回一个账户的借方不等于另一个账户的贷方的交易条目。
有什么帮助吗?
提前致谢。
我的尝试:
SELECT debit,credit FROM transactionentries
where glaccountid = 15374
and debit not in (
SELECT credit FROM transactionentries where glaccountid = 15376
);
上面的查询不返回任何行,我希望返回一个帐户的借方不等于另一个帐户的贷方的交易条目。
解决方案
select * from transactionentries s where not exists (select 1 from transactionentries p where p.debit=s.credit and s.debit=p.credit);
推荐阅读
- mongodb - 在 mongodb shell 中打印回车符
- java - Minecraft 服务器使用所有 CPU
- c++ - How to allocate memory to a 2D array of objects in c++?
- java - 我创建了该方法,但无法在 main 中调用它
- postgresql - 在 Mac 上忘记 PostgreSQL 13 db 的密码
- ios - 嵌套数组过滤器 swift
- android - 在 Android 上绘制边缘叠加
- django - 添加到购物车功能未执行
- sql - 用户在过去 n 天组中运行的中位数。大查询 SQL
- kubernetes - 有什么不同的 --dry-run 机会?