How to write sphinx queries with OR condition

耗尽温柔 提交于 2019-12-24 03:42:10

问题


I need to create a sphinx query in my project with OR condition. But giving an OR condition like

select cost FROM transactionsChart WHERE cost=25 OR cost=5;

is not working. It returns an error like

ERROR 1064 (42000): sphinxql: syntax error, unexpected OR, expecting $end near 'OR cost=5'

Can anybody help me....

Thanks in advance


回答1:


Sphinx doesnt support OR in the WHERE clause, only AND.

For your specific example, could use IN syntax,

sphinxql> SELECT cost FROM transactionsChart WHERE cost IN (5,25);

or a more general solution is to use a virtual attribute

sphinxql> SELECT cost, IF(cost=25 OR cost=5,1,0) AS filter 
      FROM transactionsChart WHERE filter = 1;



回答2:


Try with

select cost FROM transactionsChart WHERE cost=25 | cost=5;

Source - Official Documentation



来源:https://stackoverflow.com/questions/31199579/how-to-write-sphinx-queries-with-or-condition

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!