读书人

请求帮忙优化一个sql语句啊该怎么解决

发布时间: 2012-03-16 16:34:56 作者: rapoo

请求帮忙优化一个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);

的结果贴出来看一下。

读书人网 >Mysql

热点推荐