昨天领导帮我优化了一下sql语句。
test表结构
a b
1 2
3 4
5 6
7 8
1 6
9 10
我之前写的sql语句,例:
select a,b
from test
where (a = 1 and b = 2)
or (a = 3 and b = 4)
or (a = 5 and b = 6)
or (a = 9 and b = 10);
领导优化后:
select a,b from test where (a,b) in ((1,2),(3,4),(5,6),(9,10));
我在网上搜一下之后,原来mysql的in条件就能大大简化这种sql,记录一下,以免下次再忘记。