本文介绍了我如何...如何将重复的行添加为除sql中的一列之外的新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表tableName是tblProduct ...
表是
ID产品客户
1 Lux Hari
2 Dove Ram
2 Pears Banu
我需要将最后两行添加到同一个表中,除了像这样的ID ...
ID产品客户
1 Lux Hari
2 Dove Ram
2 Pears Banu
3 Dove Ram
3梨Banu
I have one table tableName is tblProduct...
the table is
ID Product Customer
1 Lux Hari
2 Dove Ram
2 Pears Banu
I need to add the Last two rows into the same table except id like this...
ID Product Customer
1 Lux Hari
2 Dove Ram
2 Pears Banu
3 Dove Ram
3 Pears Banu
推荐答案
insert into tblProduct(Product,Customer) select Product,CustomerFrom tblProduct where id in (select max(id) from tblProduct union select max(id)-1 from tblProduct)
insert into tblProduct(id,Customer,Product)
(select TOP 2 id+1,Customer,Product
From tblProduct
group by id,Product,customer )order by id desc
这篇关于我如何...如何将重复的行添加为除sql中的一列之外的新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!