-1

我收到以下 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')
4

3 回答 3

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')
于 2013-01-18T22:07:02.657 回答
2

你不能放在NOT表达式的中间,它在表达式之前:

NOT start_date < '2013-01-14'

或者使用运算符的补码<,即>=

start_date >= '2013-01-14'

(使用的例外NOTIS NULL运算符,其中NOT x IS NULL和都x IS NOT NULL起作用。)

于 2013-01-18T22:16:58.797 回答
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')
于 2013-01-18T22:08:30.390 回答