MySQL使用一组值插入表中

时间:2014-04-25 21:25:51

标签: mysql sql

我需要插入一个包含一些值的表格(例如:' NDA'在这种情况下)。如果我只插入一个值,这似乎很有效。我有大约十几个类似的值,是否有一个我可以调整此查询插入说{' NDA',' SDM',' APM' }值。很想知道是否可以在没有存储过程的情况下完成,或者复制粘贴相同的语句并更改值。

INSERT IGNORE INTO customer_feature (customer_id, feature)
SELECT c.id, 'NDA' FROM
customer as c
where c.edition = 'FREE_TRIAL';

参考:mysql -> insert into tbl (select from another table) and some default values

1 个答案:

答案 0 :(得分:2)

这是你想要的吗?

INSERT IGNORE INTO customer_feature(customer_id, feature)
    select c.id, f.feature
    from customer c cross join
         (select 'NDA' as feature union all select 'SDM' union all select 'APM'
         ) f
    where c.edition = 'FREE_TRIAL';