日期:2014-05-17  浏览次数:20754 次

oracle一个性能优化的sql...
有一个sql语句想优化下,看过很多文章说不用in,可是不知道该如何修改:
  select work.Id from table01 as work where (work.Id = 01 
  or work.workId in (select p.workId from table02 as p
  where p.PId=01)) and work.isDel<>1 and work.workDate between ? and ?
  order by work.workDate,work.beginTime;
我创建了一个索引 字段是 workDate。其他的方式该怎么搞?能不能用视图,怎么用啊?....

------解决方案--------------------
SQL code
(work.Id = 01 
or work.workId in (select p.workId from table02 as p
where p.PId=01))

------解决方案--------------------
select work.Id,work.workDate,work.beginTime
 from table01 as work 
where work.Id = 01 
and work.isDel<>1 
and work.workDate between ? and ?
union all
select work.Id,work.workDate,work.beginTime
 from table01 as work,table02 as p 
where p.PId=01 and work.workId = p.workId
and work.isDel<>1 and work.workDate between ? and ?
order by workDate,beginTime;