34,590
社区成员
发帖
与我相关
我的任务
分享
t1 t2
id file2 file3 file1 file2
1 1 2 1 1
2 2 3 2 3
3 3 2 1 2
3 4
字段1 字段2 字段3 (字段1和字段2为表的主键)
a 1 s
a 2 d
a 3 s
a 4 d
b 1 s
b 2 d
b 3 s
b 4 s
b 5 d
b 6 d
c 1 a
c 2 s
c 3 a
-1
update t2
set file1 = t1.id
from t2 inner join t1
on t2.file2 = t1.file2
-2 使用row_number,rank通过partition by分区 排序可解决 但是在2005版本中
select col1,col2,col3 from
(select col1,rank() over(partition by col1 order by col1 asc) as col2,col3 form tb) as a
;with aa as (
select 字段1,字段3,row_number() over (partition by 字段1 order by select 1 )as 字段2
from tb
)
select 字段1 字段2 字段3
from aa
update t2 set file1=t1.id
from t1,t2
where t2.file2=t1.file2
update t2
set file1 = t1.id
from t2 , t1
where t2.file2 = t1.file2
--1
update t2 set file1=t1.id
from t1,t2 where t2.file2=t1.file2