select * from tbTriopticsRowDataHistory not in (select * from tbTriopticsRowDataHistory where (operator like '%10CM%' and matchtype<>'T') or (operator not like '%10CM%' and matchtype<>'M' ) )
要怎么修改
select * from tbTriopticsRowDataHistory where 表的主键 not in (select 表的主键 from tbTriopticsRowDataHistory where (operator like '%10CM%' and matchtype<>'T') or (operator not like '%10CM%' and matchtype<>'M' ) )
感觉这样效率不高啊!
本身的sql就有问题, not in 改用 not exists ,or 拆开改成 uion (all),这样会好很多
这样会快:
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