gpt4 book ai didi

mysql - 无法将查询结果插入到 phpMyAdmin 中的 SQL 查询中

转载 作者:行者123 更新时间:2023-11-30 22:36:03 25 4
gpt4 key购买 nike

我正在运行以下查询:

SELECT *
INTO consolidated
FROM (SELECT qtyAvailable
FROM Inventory
UNION ALL
SELECT revenue,
location,
qtySold
FROM sales
UNION ALL
SELECT inactive,
new,
itemNum,
category,
subCategory,
color,
FROM Masterlist) n

得到这些错误

    Error
SQL query: Documentation


SELECT *
INTO consolidated
FROM (SELECT qtyAvailable
FROM Inventory
UNION ALL
SELECT revenue,
location,
qtySold
FROM sales
UNION ALL
SELECT inactive,
new,
itemNum,
category,
subCategory,
color,
FROM Masterlist) n
LIMIT 0, 25
MySQL said: Documentation

#1327 - Undeclared variable: consolidated

当我删除新表或“变量”时出现此错误

Error
SQL query: Documentation


SELECT *
FROM (SELECT qtyAvailable
FROM Inventory
UNION ALL
SELECT revenue,
location,
qtySold
FROM sales
UNION ALL
SELECT inactive,
new,
itemNum,
category,
subCategory,
color,
FROM Masterlist) n
LIMIT 0, 25
MySQL said: Documentation

#1064 - 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 'FROM Masterlist) n
LIMIT 0, 25' at line 16

当我删除 n 时,出现类似的错误

Error
SQL query: Documentation


SELECT *
FROM (SELECT qtyAvailable
FROM Inventory
UNION ALL
SELECT revenue,
location,
qtySold
FROM sales
UNION ALL
SELECT inactive,
new,
itemNum,
category,
subCategory,
color,
FROM Masterlist)
LIMIT 0, 25
MySQL said: Documentation

#1064 - 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 'FROM Masterlist)
LIMIT 0, 25' at line 16

我对 myPHP 没有很深的经验,但基本上我在数据库中的三个表上运行查询,我想将结果插入一个新表中,我称之为合并表。我创建了合并表并将列留空。我不知道从哪里开始,在此先感谢您的帮助!我也想出了基于这个 post 的初始查询

最佳答案

在导致第二个错误的最后一个 from 子句之前有一个多余的逗号。无论如何,MySQL 不支持 select ... into 语法。相反,您应该使用 insert ... select 语法:

INSERT INTO consolidated 
SELECT *
FROM (SELECT qtyAvailable
FROM Inventory
UNION ALL
SELECT revenue,
location,
qtySold
FROM sales
UNION ALL
SELECT inactive,
new,
itemNum,
category,
subCategory,
color -- redundant comma removed here
FROM Masterlist) n

关于mysql - 无法将查询结果插入到 phpMyAdmin 中的 SQL 查询中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32517405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com