【发布时间】:2016-03-08 10:23:45
【问题描述】:
我正在创建一个图书馆系统,每本书只有 1 个副本。用户将输入这本书和他们想要的日期。在系统将检查该书是否未为用户想要的日期保留之后。
如果变量不在表中,我正在尝试将数据插入表中。例如如果 id 等于 3 并且日期介于表中已有的两个日期之间,则不会输入信息。该表用于简单的预订系统。下面的代码是我所拥有的,但似乎不起作用,因此需要更改。我得到的错误低于代码。谢谢。
SELECT *
FROM `table_name`
INSERT INTO table_name (name, id, start_date, end_date, days)
VALUES ('test', '4', '0000-00-00', '1000-00-00', 3)
WHERE id != 3
AND start_date NOT BETWEEN 2016-03-31 AND 2016-03-05
这是我运行代码时遇到的错误:
Static analysis:
9 errors were found during analysis.
Unrecognized keyword. (near "NOT" at position 203)
Unrecognized keyword. (near "BETWEEN" at position 207)
Unexpected token. (near "2016" at position 215)
Unexpected token. (near "-03" at position 219)
Unexpected token. (near "-31" at position 222)
Unrecognized keyword. (near "AND" at position 226)
Unexpected token. (near "2016" at position 230)
Unexpected token. (near "-03" at position 234)
Unexpected token. (near "-05" at position 237)
SQL query: Documentation
SELECT * FROM `table_name` INSERT LIMIT 0, 25 INTO table_name (name, id, start_date, end_date, days) VALUES ('test', '4', '0000-00-00', '1000-00-00', 3) WHERE id != 3 AND start_date NOT BETWEEN 2016-03-31 AND 2016-03-05
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT LIMIT 0, 25 INTO table_name (name, id, start_date, end_date, days)' at line 3#
【问题讨论】:
-
首先你的insert into - select语法不正确。
-
@Smudger 您的插入语句中不能有 where 子句,因为您正在插入数据
标签: mysql sql select insert-into