sql - 如何将左连接与第二个选择语句一起使用?
问题描述
我的应用中有查询 1。但是,我面临NOT IN
(太慢)的性能问题。所以,我试图用LEFT JOIN
. 如何编写查询?还有更好的选择吗?
查询 1 =
SELECT COUNT(id)
FROM Payment
WHERE gl_posting LIKE :glposting
AND id NOT IN (SELECT PAYMENT_ID
FROM UNPOST_REQUEST_P
WHERE status NOT LIKE :status );
我试过了
SELECT COUNT(id)
FROM Payment
WHERE gl_posting LIKE :glposting
AND id LEFT JOIN (SELECT PAYMENT_ID
FROM UNPOST_REQUEST_P
WHERE status NOT LIKE :status );
但是,我得到一个错误
[42000][920] ORA-00920: 无效的关系运算符
解决方案
尝试not exists
提高性能
select
count(id)
FROM Payment p
where gl_posting like :glposting
and not exists (
select
payment_id
from UNPOST_REQUEST_P ur
where p.id = ur.payment_id
and status not like :status
)
此外,您应该首先学习如何使用左连接(或任何连接)。
推荐阅读
- java - Struts 2.5 运行 Junit 4 测试并在查找 Struts 插件父包时遇到运行时错误
- java - 按文件打开程序
- scala - Spark:将多列分解为一列
- python - 在页面源 selenium python 中查找某些文本
- pandas - 有效地从具有 groupby 和时间条件的 Pandas DataFrame 中删除行?
- android-layout - ListPreference 列表选项文本颜色
- wcf - 通过 WCF 服务上传大于 8 MB 的流
- vue.js - 通过事件总线 -Vue js 呈现的项目
- permissions - 如何解决此错误消息?Azure DevOPs TF401232:工作项不存在,或者您没有读取它的权限
- assembly - MIPS 中的运行时异常地址超出范围