创建表,如果不是XY( x INT NOT NULL, y FLOAT NULL, 主要关键(x) )
INSERT INTO XY (x,y)
(select 1 as x ,(1/7) as y);
错误
Error code 1064, SQL state 42000: 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 INTO XY (x,y)
(select 1 as x ,(1/7) as y)' at line 7
Line 1, column 1
任何想法?
答案 0 :(得分:1)
您应该在CREATE TABLE
语句之后(或INSERT
语句之前)添加; 。您正在尝试执行2个不带分隔符的不同查询。
CREATE TABLE IF NOT EXISTS XY (
x INT NOT NULL ,
y FLOAT NULL ,
PRIMARY KEY(x)
); # !!! Originally, you missed ;
INSERT INTO XY (x,y)
(select 1 as x ,(1/7) as y);
答案 1 :(得分:0)
你需要围绕select语句的括号
INSERT INTO XY (x,y)
select 1 as x ,(1/7) as y;