update t set fieldb=(select count(distinct fielda) from t a where a.fielda<=t.fielda)

解决方案 »

  1.   

    根据fielda分组,并把每组的fieldb分别改成1,2,3...,应该每个不同的fielda的记录都是1,2,3...
      

  2.   

    update t set fieldb=(select count(*) from t a where a.fielda=t.fielda and a.fieldb<=t.fieldb)
      

  3.   

    还是不对的,你自己验证一下,下面是我执行后的结果:
    fielda   fieldb
    1 3
    1 3
    1 3
    2 3
    2 3
    2 3
    3 1
      

  4.   

    你需要得到的结果是不是fielda   fieldb
    1 1
    1 1
    1 1
    2 2
    2 2
    2 2
    3 3
      

  5.   

    你的fieldb赋值后都是递增顺序得么?那么一句sql是不成的啊
      

  6.   

    如果在SQL Server中,可以写为:
    update YourTab
    set fieldb = (select count(distinct fielda)
                  from YourTab t1 where t1.fielda <= fielda)注意 update YourTab 中不能用 as 
    count(distinct fielda) 是另一个关键点