这条sql语句执行的速度相当慢啊,有没有什么地方可以优化一下,哪怕提高一点点速度也行啊,谢谢select min(right(code,4)) from customer
where code like 'US%' and right(code,4)+1 not in(select right(code,4) from customer);

解决方案 »

  1.   

    select min(right(a.code,4)) from customer a
    left join customer b on right(a.code,4)+1=right(b.code,4)
    where a.code like 'US%' and b.code is null
      

  2.   

    explain select min(right(code,4)) from customer
    where code like 'US%' and right(code,4)+1 not in(select right(code,4) from customer);的结果贴出来看一下。
      

  3.   

    code 上加个索引。
    not in 想办法改成not exists