昨天领导帮我优化了一下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,记录一下,以免下次再忘记。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-04
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-25
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案