MySQL 插入...选择 #1054 错误

发布于 2024-08-01 13:58:52 字数 926 浏览 11 评论 0原文

任何人都可以帮忙吗..

SELECT 自己可以工作,

INSERT 可以单独使用 VALUES 也可以工作。

注意:

 products_similar has 2 columns VARCHARS
 get_cheaper() - stored routine returning VARCHAR

我从来没有遇到过 INSERT INTO ... SELECT 问题。

但是当我将它们组合起来时,出现以下错误:

SQL 查询:文档

INSERT INTO `products_similar` (
`product_sku` ,
`better_priced_sku`
)
SELECT p.product_sku sku, get_cheaper(
p.product_sku
)cheaper_sku
FROM jos_vm_product p;

MySQL 说:文档

字段列表”中的未知列“product_sku”它有效:

#1054 -当我注释掉 get_cheaper(p.product_sku) Cheap_sku 时,“

TRUNCATE TABLE `products_similar` ;# MySQL returned an empty result set (i.e. zero rows).
INSERT INTO `products_similar` (
`product_sku` ,
`better_priced_sku`
)
SELECT p.product_sku sku, p.product_sku sku# , get_cheaper(p.product_sku) cheaper_sku

FROM jos_vm_product p;# Affected rows: 43882

Can anybody please help..

SELECT on its own works

INSERT on its own with VALUES works also.

note:

 products_similar has 2 columns VARCHARS
 get_cheaper() - stored routine returning VARCHAR

I never ever had problems with INSERT INTO ... SELECT.

But when I combine them I get error below:

SQL query: Documentation

INSERT INTO `products_similar` (
`product_sku` ,
`better_priced_sku`
)
SELECT p.product_sku sku, get_cheaper(
p.product_sku
)cheaper_sku
FROM jos_vm_product p;

MySQL said: Documentation

#1054 - Unknown column 'product_sku' in 'field list'

when I comment out get_cheaper(p.product_sku) cheaper_sku it works:

TRUNCATE TABLE `products_similar` ;# MySQL returned an empty result set (i.e. zero rows).
INSERT INTO `products_similar` (
`product_sku` ,
`better_priced_sku`
)
SELECT p.product_sku sku, p.product_sku sku# , get_cheaper(p.product_sku) cheaper_sku

FROM jos_vm_product p;# Affected rows: 43882

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

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

发布评论

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

评论(3

鲜肉鲜肉永远不皱 2024-08-08 13:58:52

据推测,这是由于重命名所致:SELECT p.product_sku sku。 预期的列名称为product_sku。

Presumably this is due to the rename: SELECT p.product_sku sku. A column name of product_sku is expected.

怎会甘心 2024-08-08 13:58:52

您的查询的这一部分可以单独工作吗?

SELECT p.product_sku sku, get_cheaper(p.product_sku)cheaper_sku
FROM jos_vm_product p;

编辑:

既然可行,请尝试从中创建一个视图。

CREATE VIEW products_similar 
AS SELECT p.product_sku sku, get_cheaper(p.product_sku)cheaper_sku
FROM jos_vm_product p;

您将能够像普通表一样查询视图

Does this part of your query work by it self?

SELECT p.product_sku sku, get_cheaper(p.product_sku)cheaper_sku
FROM jos_vm_product p;

Edit:

Since that works, try creating a view from it.

CREATE VIEW products_similar 
AS SELECT p.product_sku sku, get_cheaper(p.product_sku)cheaper_sku
FROM jos_vm_product p;

You will be able to query the view just like a normal table

别再吹冷风 2024-08-08 13:58:52

这是mysql手册对此问题的答案:

以下列定义演示了每种可能性:

自动初始化和自动更新:
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

仅自动初始化:
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP

仅自动更新:
ts TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP

两者都不是:
ts TIMESTAMP DEFAULT 0

您对最后一个感兴趣 - 如果您将时间戳的默认值设置为 0,它将不会自动更新

Here is the answer to this question from mysql manual:

The following column definitions demonstrate each possibility:

Auto-initialization and auto-update:
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

Auto-initialization only:
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP

Auto-update only:
ts TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP

Neither:
ts TIMESTAMP DEFAULT 0

You are interested in the last one - if you set the default value of the timestamp to 0 it will not be automaticly updated

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