-1

我有一张这样的桌子

会员卡

AssoicaticeCard      MainCard  custID
A                       A           1
B                       B           1
C                       A           1
AA                      AA          2
BC                      BC          2
CC                      CC          2
Ar                      Ar          3
Bs                      Bs          3
Cv                      Cv          3

现在我需要像这样设置结果,其中我的 AssoicaticeCard 和 MainCard 已正确链接。

我需要显示这样的结果。如何为此编写更新语句来实现?

AssoicaticeCard      MainCard  custID
A                       A           1
B                       A           1
C                       A           1
AA                      AA          2
BC                      AA          2
CC                      AA          2
Ar                      Ar          3
Bs                      Ar          3
Cv                      Ar          3

我有一个表,其中的数据不一致,现在需要编写一个更新语句来解决这个问题。我的表有大约 100 万条记录。

4

2 回答 2

2
update T1
set MainCard = T2.AssoicaticeCard
from YourTable as T1
  inner join
      (
        select min(AssoicaticeCard) as AssoicaticeCard,
               custID
        from YourTable
        group by custID
      ) T2
    on T1.custID = T2.CustID
于 2012-05-04T08:01:03.260 回答
0
update clubcard set Maincard = 'A' where custID = 1;
update clubcard set Maincard = 'AA' where custID = 2;
update clubcard set Maincard = 'Ar' where custID = 3;
于 2012-05-04T07:10:44.383 回答