insert,将一个表中的部分数据复制到另一个表中

工作中经常会遇到插入一条数据,该数据可能包含固定值,也可能是另一张表中的查询结果
解决该问题分两种情况:
1、当table2存在时:

insert into table1 (x1,x2) values('a',(select x from table2 where x=x))

2、当table2不存在时:

insert into table1(x1,x2) select 'a' , x from table1 where where x=x

转载于:https://www.jianshu.com/p/a9304c4c940d

猜你喜欢

转载自blog.csdn.net/weixin_34066347/article/details/91190938