首页 新闻 会员 周边 捐助

这句SQL 怎么修改

0
[待解决问题]
select * from tbTriopticsRowDataHistory  not in 
(select * from tbTriopticsRowDataHistory 
where
 (operator like '%10CM%' and matchtype<>'T')
 or 
(operator not like '%10CM%' and matchtype<>'M' )
)

要怎么修改

Sureboy的主页 Sureboy | 菜鸟二级 | 园豆:212
提问于:2012-09-18 18:03
< >
分享
所有回答(4)
0
select * from tbTriopticsRowDataHistory where 表的主键 not in 
(select 表的主键 from tbTriopticsRowDataHistory 
where
 (operator like '%10CM%' and matchtype<>'T')
 or 
(operator not like '%10CM%' and matchtype<>'M' )
)
向往-SONG | 园豆:4853 (老鸟四级) | 2012-09-18 22:22
0

感觉这样效率不高啊!

jason2013 | 园豆:1998 (小虾三级) | 2012-09-19 08:48
0

本身的sql就有问题, not in 改用 not exists  ,or 拆开改成 uion (all),这样会好很多

cobby | 园豆:211 (菜鸟二级) | 2012-09-19 09:34
0

这样会快:

select TA.*  
from tbTriopticsRowDataHistory TA
LEFT JOIN tbTriopticsRowDataHistory TB on TA.id=TB.id

and ((TB.operator like '%10CM%' and TB.matchtype<>'T')
or
(TB.
operator not like '%10CM%' and TB.matchtype<>'M' ))
where TB.id is null

ihoneycomb | 园豆:202 (菜鸟二级) | 2012-09-19 17:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册