在选择错误中插入...选择除法运算符?

发布于 2024-09-04 14:24:58 字数 440 浏览 6 评论 0原文

如果不存在则创建表 XY ( x 整数不为空, y 浮点数为空, 主键(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

有任何想法

CREATE TABLE IF NOT EXISTS XY (
x INT NOT NULL ,
y FLOAT NULL ,
PRIMARY KEY(x)
)

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

errors with

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

any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦一生花开无言 2024-09-11 14:24:58

您应该在 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);

You should add ; after CREATE TABLE statement (or before INSERT statement) . You are trying to execute 2 different queries without separator.

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);
剧终人散尽 2024-09-11 14:24:58

select 语句需要加括号吗

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

do you need the parentheses around the select statement

INSERT INTO XY (x,y)
select 1 as x ,(1/7) as y;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文