0

如果不存在 XY ( x INT NOT NULL , y FLOAT NULL , PRIMARY KEY(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

有任何想法吗?

4

2 回答 2

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);
于 2010-06-07T18:06:40.773 回答
0

你需要选择语句周围的括号吗

INSERT INTO XY (x,y)
select 1 as x ,(1/7) as y;
于 2010-06-07T18:01:50.650 回答