0
set row pro1 pro2  Dup
1   1   AB2  AB2
1   1   AB6  AB4
1   1   AB2  NB3
2   1   AN2  QW3  
2   2   BH1  BH1
3   1   AJ1  AJ1
4   1   HU3  HU3
4   1   BH2  BH2

我想填充dup = 'Case1'给定集合的位置,pro1 = pro2; 要求该集中有超过 1 条记录。预期结果:

set row pro1 pro2  Dup
1   1   AB2  AB2   CASE1
1   1   AB6  AB4   NULL
1   1   AB2  NB3   NULL
2   1   AN2  QW3   NULL
2   2   BH1  BH1   CASE1 
3   1   AJ1  AJ1   NULL   (even though it matches, but its just one record)
4   1   HU3  HU3   CASE1
4   1   BH2  BH2   CASE1
4

1 回答 1

1
with C as
(
  select pro1,
         pro2,
         dup,
         count(*) over(partition by [set]) as setcount
  from YourTable
)
update C
set dup = 'CASE!'
where pro1 = pro2 and
      setcount > 1

SE-Data 的工作样本

于 2012-04-17T05:40:12.463 回答