读书人

求大神帮小弟我优化这个sql语句

发布时间: 2013-06-19 10:26:41 作者: rapoo

求大神帮我优化这个sql语句
select distinct userid from userlog where userid not in(select distinct userid from #user)
and accesstime >='2013-04-27' and accesstime<'2013-04-28';


怎么修改? 现在效率太低
[解决办法]

select distinct  userid 
from userlog t
where
not exists(select userid from #user t1 where t.userid=t1.userid)
and accesstime >='2013-04-27' and accesstime<'2013-04-28';

userlog以及#user表中userid设置索引
userlog中创建accesstime索引

http://www.cnblogs.com/worfdream/articles/3040204.html

读书人网 >SQL Server

热点推荐