1

我的表结构是:

id | type | attribute | customer_id | value

1 | 2 | 1 | 1 | some
2 | 2 | 2 | 1 | this
3 | 2 | 3 | 1 | that
4 | 2 | 1 | 2 | cool
5 | 2 | 2 | 2 | just

ETC

我想将value ='mine' 作为属性4 添加到每个customer_id

INSERT INTO mytable 
SET type='2', attribute='4, value='mine'

问题是如何将它绑定在 customer_id 上并且每个客户只绑定一次?

4

1 回答 1

1
INSERT INTO myTable(type, attribute, customer_id, value)
SELECT  2 type,
        4 attribute,
        s.customer_id,
        'mine' `value`
FROM    (SELECT DISTINCT customer_id FROM myTable) s
于 2013-10-30T14:49:35.133 回答