Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 从子查询插入_Mysql_Magento - Fatal编程技术网

Mysql 从子查询插入

Mysql 从子查询插入,mysql,magento,Mysql,Magento,我试图根据子查询的结果进行插入,但始终出现相同的错误: 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 WHE

我试图根据子查询的结果进行插入,但始终出现相同的错误:

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
    )
))
如何为插入选择多个列?

请尝试dis:

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
    )
试一试dis:

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
    )

您需要使用
插入到…从中选择,而不是
插入到..值中

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)

您可以在
选择
列表中为您的
属性id

添加一个静态值,您将希望使用
插入到…选择从
而不是
插入到..值中

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)

您可以在
属性id的
选择
列表中包含一个静态值。请尝试以下代码

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
   )

请尝试以下代码

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
   )

完美,这是一种享受,我会接受它让我尽快完美,这是一种享受,我会接受它让我尽快