sql - 我想调整下面的查询
问题描述
SELECT GRIRNO,GRIRDATE,CLRD_ON
FROM GRIR_PASS
WHERE APRVD_BY IS NOT NULL and
grirno not in
(select grirno
from grirmain
where rcvd_by is not null
)
ORDER BY
TO_NUMBER(substr(GRIRNO,instr(GRIRNO,'/',1,1)+1,(instr(GRIRNO,'/',1,2)-instr(GRIRNO,'/',1,1)-1)));
解决方案
您可以使用 MINUS 而不是 not in 来选择涉及的 GRIRNO 从两个表 GRIR_PASS 和 grirmain
select GRIRNO,GRIRDATE,CLRD_ON
from GRIR_PASS
inner join (
select GRIRNO
FROM GRIR_PASS
WHERE APRVD_BY IS NOT NULL
minus
select grirno
from grirmain
where rcvd_by is not null
) t on t.GRIRNO = GRIR_PASS.GRIRNO
ORDER BY
TO_NUMBER(substr(GRIRNO,instr(GRIRNO,'/',1,1)+1,(instr(GRIRNO,'/',1,2)-instr(GRIRNO,'/',1,1)-1)));
推荐阅读
- aws-lambda - 将现有 DynamoDB 项目导出到 Lambda 函数
- javascript - 删除 Array javascript 或 typescript 中的重复对象
- sql - UNION和OR之间的功能区别是什么?
- c# - AutoMapper 利用 HasDefaultValueSql
- python - TypeError:使用字符串拆分将参数传递给json api时,字符串索引必须是整数
- java - 具有来自依赖项的配置文件的弹簧启动属性
- exception - 有例外的公共交通传奇
- apache-spark - 如何解析包含表示 JSON 的字符串属性的 JSON
- javascript - v-on 处理程序变量 this 中的 VueJS 错误。未定义
- python - 如何将一列逗号分隔的字符串中的每个值提取到单独的行中?