当前位置: 代码迷 >> Sql Server >> 求优化这句sql解决思路
  详细解决方案

求优化这句sql解决思路

热度:77   发布时间:2016-04-24 09:53:33.0
求优化这句sql
本帖最后由 huliangsc 于 2014-10-13 10:24:53 编辑
select top 18 id,bumid,buname,buimg,bumebtype from bloguser where buptid=66 and bumid<>282 and bumid not in( select bfid from BlogFriends where mid=282) order by NewID()
------解决思路----------------------
not in 换 not exists试试

and not exists (select 1 from BlogFriends where mid=282 and bloguser.bumid = bfid)
------解决思路----------------------

select * from (select id,bumid,buname,buimg,bumebtype from bloguser 
where buptid=66 and bumid<>282 ) as a left join blogfriends as b
on b.mid=282 and a.bumid=b.bfid
where b.bfid is null
order by NewID()


试试 貌似效率不会提高吧
  相关解决方案