表A
数据如下 :月份   工号 字段1
200701 111  12
200702 111  11
200703 111  11
200701 222  13
200702 222  12
200703 222  12要求
 替换 月份 为 200702、200703 行  的“字段1” 数据
      若同1个工号 “字段1” 的数据 与 200701行数据不一致时, 替换成 200701 行的字段1 的数据替换结果  如下月份   工号 字段1
200701 111  12
200702 111  12
200703 111  12
200701 222  13
200702 222  13
200703 222  13 200702、200703 没有记录的时 忽略

解决方案 »

  1.   

    ORACLE确实人气不如SQL SERVER旺
      

  2.   

    upate A s set 字段1= (select 字段1 from A t where t.工号=t.工号 and t.月份=200701 )
      

  3.   

    update 表A t1 set 字段1 = (select 字段1 from 表A t2 where t2.月份 = '200701' and t1.工号 = t2.工号);不知道你的月份是否是日期类型,如果是,还要用to_char()函数转换一下
      

  4.   

    --月份是字符串类型时:
    update 表A t set t.字段1=(select 字段1 from 表A where 工号=t.工号 and 月份='200701'and rownum=1) where t.月份 in('200702','200703')
    and exists(select 1 from 表A where 工号=t.工号 and 月份='200701')
    --月份是DATE类型时:
    update 表A t set t.字段1=(select 字段1 from 表A where 工号=t.工号 and to_char(月份,'YYYYMM')='200701'and rownum=1) where to_char(t.月份,'YYYYMM') in('200702','200703')
    and exists(select 1 from 表A where 工号=t.工号 and to_char(月份,'YYYYMM')='200701')
      

  5.   

    update 表A t1 set 字段1 = (select 字段1 from 表A t2 where t2.月份 = '200701' and t1.工号 = t2.工号 AND T1.字段1<>T2.字段1);这样可以吗?
      

  6.   

    update table T1 set 字段1=(select 字段1 from table T2 where T1.月份=T2.月份 and T1.工号=T2.工号)where T1.月份 !='200701'
      

  7.   

    update table set table.字段1=(select 字段1 from (select distinct 工号,字段1 from table where 月份='200701') b 
    where table.工号=b.工号)
      

  8.   

    update table set 字段1=(select 字段1 from table  T2 where T2.月份= '200701' and table .工号=T2.工号) where table  !='200701'已经进行了验证。