insert ...在选择错误中选择除运算符?

时间:2010-06-07 17:58:51

标签: mysql select insert mysql-error-1064 division

创建表,如果不是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

任何想法?

2 个答案:

答案 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;