有一张表A,表A有两个字段如下(空白的代表空值):
ID             NUMBER
33               9  
                 9
20               8
21               5
13               7
                 7
                 7
                 7
18               10
                 10
11               6
例如第一条记录ID=33,NUMBER=9,第二条记录ID为空,NUMBER=9
我想把,空白的位置更新为ID=33   ,对应的当NUMBER=7时,把空白的ID位置更新为13SQL语句怎么写,请高手指教  

解决方案 »

  1.   

    update a t set id=(select id from a where number=t.number and id is not null and rownum<2)
    where id is null;
      

  2.   

    update your_table m set id = (select id from your_table where id is not null and number = m.number and rownum = 1) where id is not null;
      

  3.   

    條件寫錯了update your_table m set id = (select id from your_table where id is not null and number = m.number and rownum = 1) where id is null;
      

  4.   

    请看清楚我的意思,我是要整个表更新 不是局限于前2条记录ID 与 NUMBER为对应关系
    当ID等于空时,去查找对应的NUMBER值对应的ID值,然后更新到空的位置。
      

  5.   

    --这个保准行 
    update A t set id=(select max(id) from A where t.num=num group by num)
     where t.num in(select distinct num from A)