表A,其中有这么几个字段 ywbh,fwbh,sfyx (主键是ywbh+fwbh)
要求根据指定的ywbh ,找到ywbh相同的几条记录中的max(FWBH),然后把这个最大的fwbh的记录的sfyx置为1多谢各位。

解决方案 »

  1.   

    update tablea a set a.sfyx=1
     where exists(select 1 from tablea b where a.ywbh=b.ywbh group by b.ywbh having max(b.FWBH)=a.FWBH);update tablea a set a.sfyx=1
     where not exists(select 1 from tablea b where a.ywbh=b.ywbh and b.FWBH>a.FWBH);
      

  2.   

    --这样试试
    update tablename t
    set fwbh=1
    where exists(select 1 from 
                        (select ywbh,max(fwbh) maxfwbh 
                         from tablename group by ywbh) tt
                 where t.ywbh=tt.ywbh and t.fwbh=tt.maxfwbh)
      

  3.   

    update tablea a set a.sfyx=1
     where not exists(select 1 from tablea b where a.ywbh=b.ywbh and b.FWBH>a.FWBH);
      

  4.   

    --试试:
    update tab a set sfyx=1 where ywbh='指定的值' 
    and not exists(select 1 from tab where  a.ywbh=ywbh  and a.fwbh<fwbh)
      

  5.   

    UPDATE A t
    SET sfyx = 1
    WHERE EXISTS(
    SELECT 1 FROM (
    SELECT ywbh,MAX(fwbh) maxfwbh 
    FROM A GROUP BY ywbh) tt
    )
    WHERE t.ywbh=tt.ywbh AND t.fwbh = tt.maxfwbh
    ) or 
    UPDATE A t 
    SET sfyx = 1
    WHERE NOT EXISTS(
    SELECT 1 FROM A tt WHERE tt.ywbh = t.ywbh AND tt.fwbh > t.fwbh
    );
      

  6.   


    UPDATE A t
    SET sfyx = 1
    WHERE NOT EXISTS(SELECT * FROM A WHERE t.ywbh=wybh AND t.fwbh<fwbh) ;
      

  7.   

    --既然是指定的 就in
    update tb a set sfyx=1
    where FWBH in(select max(FWBH) from tb b where ywbh=指定的 and a.ywbh=b.ywbh)