MySQL:使用 BETWEEN 进行多个 AND 查询?
我见过一位同事在这些条件下使用它从表中获取用户:
SELECT * FROM users WHERE gender ='male'
AND activated='yes'
AND date_registered BETWEEN '$date1' AND '$date2'
他说存在问题(当 ANDactivated='yes'
也放在那里时,它不会输出任何行,但没有抛出 MySQL 错误。
您是否需要将其放在括号或其他疯狂的内容中才能将 BETWEEN
和 AND
关联起来
?顺便一提。
I had seen a colleague use this to fetch users from a table under these conditions:
SELECT * FROM users WHERE gender ='male'
AND activated='yes'
AND date_registered BETWEEN '$date1' AND '$date2'
He said there was an problem (it not outputting any rows when the AND activated='yes'
was put there as well, but no MySQL error was thrown.
Can you not do this? Do you need to put it in brackets or something crazy to associate the BETWEEN
and AND
?
Dates are in correct format by the way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不需要括号。你已经有了正确的语法。
No brackets required. You've got the correct syntax.
不,它会工作得很好。但是,您可能希望格式化查询,以便清楚哪个
AND
是独立的,哪个属于BETWEEN .. AND ...
语句:Nope, it will work just fine. However, you might want to format your query so it is clear which
AND
is standalone, and which belongs to aBETWEEN .. AND ...
statement: