日期:2014-05-16  浏览次数:20721 次

请求帮忙优化一个sql语句啊
这条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);

------解决方案--------------------
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


------解决方案--------------------
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);

的结果贴出来看一下。