2010-06-07 31 views
0

CREATE TABLE IF NOT EXISTS XY( X INT NOT NULL, ÿFLOAT NULL, PRIMARY KEY(x)的 )insert ...在選擇錯誤時用分隔符選擇?

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 

什麼想法?

回答

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); 
+0

沒有區別嘗試,這是在找出爲什麼這個查詢不工作, INSERT INTO resultprobability(ballNumber,概率) 嘗試(選擇resultset.ballNumber ballNumber,(計數(0)/(從結果集中選擇計數(0)))概率 from resultset group by resultset.ballNumber); – Mark 2010-06-07 18:19:30

0

你需要周圍的select語句

INSERT INTO XY (x,y) 
select 1 as x ,(1/7) as y; 
+0

我已經有和沒有錯誤 – Mark 2010-06-07 18:03:44