gpt4 book ai didi

mysql - 从子查询插入

转载 作者:行者123 更新时间:2023-11-29 04:24:11 25 4
gpt4 key购买 nike

我试图根据子查询的结果进行插入,但我一直收到相同的错误:

Operand should contain 1 column(s)

这是查询:

INSERT INTO customer_entity_int

(attribute_id, entity_type_id, entity_id, `value`)

VALUES (14, (
SELECT entity_type_id, entity_id, `value`
FROM customer_entity_int
WHERE attribute_id = 13
AND entity_id NOT
IN (
SELECT entity_id
FROM customer_entity_int
WHERE attribute_id = 14
)
))

如何为我的插入选择多个列?

最佳答案

您需要使用 INSERT INTO...SELECT FROM 而不是 INSERT INTO..VALUES:

INSERT INTO customer_entity_int (attribute_id, entity_type_id, entity_id, `value`)
SELECT 14, entity_type_id, entity_id, `value`
FROM customer_entity_int
WHERE attribute_id = 13
AND entity_id NOT IN (SELECT entity_id
FROM customer_entity_int
WHERE attribute_id = 14)

您可以在 SELECT 列表中为您的 attribute_id 添加一个静态值

关于mysql - 从子查询插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15244783/

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