【问题标题】:insert ... select with divide operator in select errors?插入...在选择错误中使用除法运算符进行选择?
【发布时间】:2010-06-07 17:58:51
【问题描述】:

如果不存在则创建表 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

有什么想法吗?

【问题讨论】:

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


    【解决方案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);
    

    【讨论】:

    • 这是试图找出为什么这个查询不起作用,INSERT INTO resultprobability (ballNumber, probability) (select resultset.ballNumber ballNumber,(count(0)/(select count(0) from结果集))按结果集分组的概率结果集.ballNumber);
    【解决方案2】:

    是否需要 select 语句周围的括号

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

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 2019-08-19
      • 2011-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-07
      • 2013-04-05
      • 1970-01-01
      相关资源
      最近更新 更多