有一个表名为“表A”,其中有一列名为“列C”,列C数值,现在的值是:0.1
0.11
0.12
0.121
0.123
1
1.2
1.21
1.3
2
....我想重整这一列,按上面的值的顺序,将该列的值重新设置为:
1
2
3
4
5
6
7
8
9该如何用SQL语句实现呢?
先谢过大家。

解决方案 »

  1.   

    update tablename set 列C=rownum
      

  2.   

    update "表A" table_a set table_a.c =
           (select table_b.rn from
                  -- 确定是按 B值 ,还是C值?
                  (select row_number() over(order by c) rn,rowid
                           from test_a) table_b
                   where table_a.rowid=table_b.rowid);
                   commit;
      

  3.   

    update tablename a set a.C= (select b.rn from (select b,c,rownumber()over(partition by b,order by 1) rn from tablename) b where a.b=b.b and b.c=a.c
      

  4.   

    ----少了个括号
    update tablename a set a.C= (select b.rn from (select b,c,rownumber()over(partition by b,order by 1) rn from tablename) b where a.b=b.b and b.c=a.c)
      

  5.   


    UPDATE (SELECT C FROM A ORDER BY C) SET C=ROWNUM
      

  6.   

    update tba a set colc=(select rn from
    (select colc,row_number() over(order by colc) rn from tba ) b where a.colc=b.colc)
    where exists(select 1 from (select colc,row_number() over(order by colc) rn from tba ) c where a.colc=c.colc)