我想从表a中复制数据并将其插入到同一个表中,并且在一列中存在差异。
例如:我有表a,列名,我想:
insert into table a (name = 'daniel')
select * from table a where phone = '000'
我希望tran能够获取表格中所有列的电话是'000' 并将它们再次插入到表a中,只有列名称会有所不同。
谢谢
答案 0 :(得分:1)
希望我能理解这个问题,如果是这样的解决方案:
INSERT INTO table2(column1,name,column3) SELECT column1,' daniel',column3 FROM table2 WHERE phone =' 000'
有用的链接:
Select, Modify and insert into the same table
https://www.w3schools.com/sql/sql_insert_into_select.asp
请告诉我你的想法或反馈 感谢
KARTHIK
答案 1 :(得分:0)
雅你可以用下面的行
插入表a(名称) 从表a中选择a.columa +''+ b.columb作为名称,其中phone ='000
如果列中有更多的哥伦布,则可以连接更多的Colums并插入单列
答案 2 :(得分:0)
我的答案代码:
select * from CatalogItems where UserId = 31406
begin tran
INSERT INTO CatalogItems (UserId,Code,Name,Price,PriceAfterTax,VatPercentage )
SELECT '31429',Code,Name,Price,PriceAfterTax,VatPercentage
from CatalogItems WHERE userid = 31406
commit