SQL查询速度很慢,要怎么才能优化,或者有更好的方法达到查询效果 declare @tyear as int,@tmonth as int set @tyear=2011 set @tmonth=10 select distinct convert(varchar(10), c.checktime, 120) as mydate, u.userid,u.name, (select convert(varchar(5), min(checktime), 108) from checkinout where convert(varchar(10), checktime, 120)=convert(varchar(10), c.checktime, 120) and userid=u.userid) as mintime, (select convert(varchar(5), max(checktime), 108) from checkinout where convert(varchar(10), checktime, 120)=convert(varchar(10), c.checktime, 120) and userid=u.userid) as maxtime from checkinout as c,userinfo as u where c.checktime between '2011-11-01' and '2011-11-30'
declare @tyear as int,@tmonth as int
set @tyear=2011
set @tmonth=10
select
mydate,
u.userid,u.name,
mintime,
maxtime
from
userinfo as u ,
(
select
userid,
convert(varchar(10), c.checktime, 120) as mydate,
convert(varchar(5), min(checktime), 108) mintime,
convert(varchar(5), max(checktime), 108) maxtime
from
checkinout
where
checktime between '2011-11-01' and '2011-11-30'
GROUP BY userid
)T
where T.userid=u.userid
order by mydate
------解决方案-------------------- 从跟底下优化吧。
------解决方案--------------------