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
答案 0 :(得分:1)
我建议将查询编写为:
select m.grirno, m.grirdate
from grirmain m
where not exists (select 1
from grir_pass p
where p.ins_check is not null and
p.grirdate > date '2013-04-01' and
p.grirno = m.grirno
) and
m.grirno is not null and
m.chkuser is not null and
m.grirdate > '2013-04-01'
order by to_number(substr(GRIRNO,instr(GRIRNO,'/',1,1)+1,(instr(GRIRNO,'/',1,2)-instr(GRIRNO,'/',1,1)-1))) desc;
您无能为力,但是可以在grir_pass(grirno, grirdate, ins_check)
上添加索引。并且在grirmain(grirdate, chkuser, grirno)
上建立索引可能会有所帮助,但这不太可能-您的日期范围很宽。
注意:
not in
值,NULL
不会达到您的期望。因此,强烈建议使用not exists
。date
关键字,因此日期常量不取决于位置设置。