删除列的值,然后按升序排列 [英] deleting values of column and then putting values in increasing order
问题描述
我已经在测试表中填充了100条记录,所有行都具有相同的内容.例如,如果我在表中有一列名为BatchId_bi
的列,那么对于从1到100开始的所有行,我都为此列插入了值100.同样,所有其他行都是相同的.当我将重复记录插入另一个数据库时,这在跟踪重复记录方面给我造成了问题.
I have populated 100 records in a test table with all the rows having same content. For example, if I have a column in the table with name BatchId_bi
then, for all the rows starting from 1 to 100, I have value 100 inserted for this column. Similarly, all other rows are identical. This is creating me problem in tracking duplicate records when I am inserting these records to another database.
有没有办法,我可以删除列BatchId_bi
的所有100个值,并为第1行插入1
中的值,为第2行插入2
中的值,依此类推,直到第100行的100
.对我来说更有意义.
Is there a way, I can delete all the 100 values for the column BatchId_bi
and insert values from 1
for row1,2
for row 2 and so on until 100
for row 100. this will make more sense to me.
请让我知道.
谢谢
推荐答案
将BatchId_bi设置为自动增量键是最好的选择. 否则,您可以尝试解决此问题
Setting up BatchId_bi as an auto increment key is the best option. Otherwise you can try this as a work around
update TABLE set BatchId_bi = 0 ;
replace into TABLE(BatchId_bi,[all your columns])
select @a:=@a+1 AS BatchId_bi,[all your columns] from(select @a:=0) A ,TABLE B
;
delete from TABLE where BatchId_bi = 0 ;
这篇关于删除列的值,然后按升序排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!