在SQL Server 2008中,我有table1,並且希望如第二個表所示更新表。 即Rn(2)的更新值1 =來自上述記錄的Rn(1)的值2。序列由Rn決定。 在這方面的任何幫助將不勝感激。來自其他行號的T-SQL更新記錄
非常感謝。
Create table Table1(ID int, value1 int, value2 int, Item varchar(10),Rn int)
insert into Table1(ID,Value2,Item,Rn) values('1','33242','Orange','1')
insert into Table1(ID,Value2,Item,Rn) values('2','67665','Orange','2')
insert into Table1(ID,Value2,Item,Rn) values('3','78765','Orange','3')
insert into Table1(ID,Value2,Item,Rn) values('4','576','Orange','4')
insert into Table1(ID,Value2,Item,Rn) values('5','906658','Orange','5')
insert into Table1(ID,Value2,Item,Rn) values('6','54435','Orange','6')
insert into Table1(ID,Value2,Item,Rn) values('7','7464','Mango','1')
insert into Table1(ID,Value2,Item,Rn) values('8','9876','Mango','2')
insert into Table1(ID,Value2,Item,Rn) values('9','2433','Mango','3')
insert into Table1(ID,Value2,Item,Rn) values('10','5654','Mango','4')
insert into Table1(ID,Value2,Item,Rn) values('11','13213','Mango','5')
insert into Table1(ID,Value2,Item,Rn) values('12','9867867','Mango','6')
insert into Table1(ID,Value2,Item,Rn) values('13','5644355','Mango','7')
insert into Table1(ID,Value2,Item,Rn) values('14','6534','Apple','1')
insert into Table1(ID,Value2,Item,Rn) values('15','343','Apple','2')
insert into Table1(ID,Value2,Item,Rn) values('16','423','Apple','3')
insert into Table1(ID,Value2,Item,Rn) values('17','7666','Apple','4')
您是否在任何地方執行任何關係?我看到一個隱含的父母子女關係,但實際上沒有定義... – 2010-12-13 20:49:43