select * from (select * from (select top 10 B.UserId,B.ComName,B.address,B.digg,B.cai,B.IsProduct,C.ComContact,C.Phone,A.sortid,c.Photo,C.qq,C.business from Sw_CompanyExtend A inner join Sw_Users B on A.comid=B.userid inner join Sw_CompanyItem C on C.UserName=B.Username where a.Classid=17 and C.bigclass like '%|17|%' order by A.sortid desc) as t1 union all select * from (select top 100 percent b.Userid,B.ComName,B.address,B.digg,B.cai,B.IsProduct,C.ComContact,C.Phone,srotid=0,C.Photo,C.qq,C.business from Sw_Users B inner join Sw_CompanyItem C on C.UserName=B.Username where B.companyinfo=1 and C.bigclass like '%|17|%' order by newID()) as t2 union all select userid=0,comname,address,digg=0,cai=0,isproduct=0,comcontact,phone,sortid=0,photo='',qq,business from Sw_Free where checked=1 and bigclass like '%|17|%') as t3
and C.bigclass like '%|17|%'无法优化
好多层啊 我的神
SQL code:
将运行速度最快的放在最里边的嵌套,然后一次的加嵌套,看看如何
一看这个语句就是高手写的,高手写的往往不好优化
记得有人说charindex比like速度好一些
charindex ('|17|',C.bigclass)>0
使用临时表会很慢吗?我觉得没必要太追求语句的技巧。
意思是这样的
1:取10条在后台做了相关类别下推广的信息
select top 10 B.UserId,B.ComName,B.address,B.digg,B.cai,B.IsProduct,C.ComContact,C.Phone,A.sortid,c.Photo,C.qq,