请问下例SQL视图如何进行进查询优化呢?先祝大家元旦节快乐!
下列视图.检索出的结果为200条记录,结果花了30秒的时间.
declare @startdate as datetime,@enddate as datetime
set @startdate='2006-11-1'
set @enddate='2006-11-2'
select b_coa.COASN,dbo.issuehistory.historyid from dbo.issuehistory inner join dbo.issuehistorydetails on dbo.issuehistorydetails.issuehistoryid=dbo.issuehistory.issuehistoryid
left outer join b_coa on dbo.issuehistorydetails.lotid=dbo.b_coa.extablepkid right outer join dbo.lot on
dbo.lot.lotid=dbo.issuehistory.historyid inner join dbo.CurrentStatus on lot.CurrentStatusid=dbo.CurrentStatus.CurrentStatusid
where dbo.CurrentStatus.lastmovedate between @startdate and @enddate and dbo.CurrentStatus.workflowstepid='Wst0100000000557' and dbo.IssueHistoryDetails.SpecId = 'Spc0100000000210'
如果单检索只需花不到1秒的时间,结果集为200条
select * from dbo.currentstatus where dbo.CurrentStatus.lastmovedate between @startdate and @enddate and dbo.CurrentStatus.workflowstepid='Wst0100000000557'
现在想使用子查询,但不知从何做手
thanks

