我在下面的SQL PDO语句中遇到语法错误,你能告诉我错误在哪里吗? 谢谢!
SELECT *
FROM events
WHERE
(start_date BETWEEN '2013-01-14' AND '2013-01-20')
OR (start_date NOT < '2013-01-14' and end_date > '2013-01-20')
答案 0 :(得分:4)
你在第一部分的日期之后错过了一个'。
SELECT * FROM events WHERE (start_date BETWEEN '2013-01-14' AND '2013-01-20') OR (start_date NOT < '2013-01-14' and end_date > '2013-01-20')
答案 1 :(得分:2)
你不能把NOT
放在表达式的中间,它在表达式之前:
NOT start_date < '2013-01-14'
或者使用<
运算符的补码,即>=
:
start_date >= '2013-01-14'
(使用NOT
的例外情况是IS NULL
运算符,其中NOT x IS NULL
和x IS NOT NULL
都有效。)
答案 2 :(得分:1)
您在2013-01-20之后错过了一个勾号
SELECT * FROM events
WHERE
(start_date BETWEEN '2013-01-14' AND '2013-01-20')
OR (start_date >= '2013-01-14' and end_date > '2013-01-20')