高效的MySQL查询方法,避免多个OR语句

时间:2017-04-14 11:59:34

标签: mysql

我对查询很新,我想知道我正在处理的查询是否有更简单的解决方案。

例如,我想得到x为5,7,9,11,13,15和17的数据。

我有一个如下的查询;

SELECT * FROM abc WHERE x = 5 or x = 7 or x = 9 or x = 11 or x = 13 or x = 15 or x = 17;

是否可以使用此查询或是否有其他更简单有效的解决方案?

修改

当我使用x = [5,7,8,11,13,15,17] vs x = [5,11,7,15,8,17,13]

时,它会影响性能吗?

X是另一个类别的ID。

1 个答案:

答案 0 :(得分:3)

这是更短但同样执行

97,[0.1,0.3,0.0,0.0,0.21052631578947367,0.7894736842105263,0.0,0.0]  
99,[0.0,0.0,0.0,0.0,0.21052631578947367,0.7894736842105263,0.0,0.0]  
96,[0.0,0.0,0.0,0.0,0.21052631578947367,0.7894736842105263,0.0,0.0] 

但请记住SELECT * FROM abc WHERE x in (5,7,9,11,13,15,17) 子句中的一个条目是in,然后它返回FALSE。