插入组合(值和选择) [英] insert combine (value and select)

查看:31
本文介绍了插入组合(值和选择)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

插入数据有多种方式:

insert into MyTable (ColA, ColB, ColC) values ('A', 'B', 'C')

insert into MyTable (ColA, ColB, ColC) select  colAA, colBB, colCC from MyTable2

有没有办法使用 insert into MyTable (ColA, ColB, ColC) select colAA, colBB, colCC from MyTable2 但不是将 colAA 值插入到 colA 中,我想总是插入那里1.

Is there way to use insert into MyTable (ColA, ColB, ColC) select colAA, colBB, colCC from MyTable2 but instead of inserting for example colAA value into colA I woulkd like to insert there always 1.

感谢帮助

推荐答案

只需在 SELECT 列表中添加一个常量

Just add a constant into the SELECT list

INSERT INTO MyTable
            (ColA,
             ColB,
             ColC)
SELECT 1,
       colBB,
       colCC
FROM   MyTable2  

这篇关于插入组合(值和选择)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆