【发布时间】:2018-12-31 06:19:30
【问题描述】:
select grirno,grirdate
from grirmain
where grirno not in
(select grirno
from grir_pass
where ins_check is not null
and grirdate > '01-apr-2013'
)
and grirno is not null
and chkuser is not null
and grirdate >'01-apr-2013'
order by to_number(substr(GRIRNO,instr(GRIRNO,'/',1,1)+1,(instr(GRIRNO,'/',1,2)-instr(GRIRNO,'/',1,1)-1))) desc
【问题讨论】:
-
欢迎来到 Stack Overflow。请尽快阅读About 和How to Ask 页面。当你问一个 SQL 问题时,请添加一个标签来识别 SQL 的方言——在本例中是 Oracle。对于 SQL 问题,您通常需要提供表的大纲架构、一些示例数据以及您从示例数据中获得和期望的结果。不幸的是,这个问题更复杂。我们需要有关表大小(行数;每行大小——整数都可以)以及表上的索引的信息。它可能过于开放,很难给出一个好的答案。
-
另见How to post a T-SQL question on a public forum — 虽然 T-SQL 不是 Oracle,但原理是一样的。
-
查询优化很困难,因为很大程度上取决于每个案例的具体情况。唉,我们不能只看您的查询并告诉您如何让它更快。请阅读this StackOverflow post,其中描述了我们在提供帮助之前需要的其他信息以及您如何获得这些信息。
-
您的查询中有太多
NOTs,其中一个或几个肯定会导致全表扫描。可能有一种方法可以通过在两张表之间使用LEFT JOIN更改NOT IN来删除其中的大部分。然而,根据您所展示的内容,不可能获得正确的指导。 我们需要表结构和数据。
标签: sql oracle performance query-optimization