问一个基础的问题,
简要描述表X的情况: xm,nd,dm同一个xm在不同的nd里可能有不同的dm现要修改表X里同一个xm里nd最小的dm值为1update X
set dm=1
where  ???

解决方案 »

  1.   

    update t set 
    dm=1
    from 表X t
    where not exists(select 1
                     from 表X
                     where xm=t.xm and nd<t.xm)
      

  2.   

    update a set dm=1 from X a where nd=(select min(nd) from X where xm=a.xm)
      

  3.   

    update X set dm=1 where nd in (select min(nd) from X group by nd)
      

  4.   

    update x1 set dm=1 from X x1 where nd=(select min(nd) from X x2 where x2.xm=x1.xm)
      

  5.   


    update x1 set dm=1 from X x1 where nd=(select min(nd) from X x2 where x2.xm=x1.xm)
      

  6.   

    update a set dm=1 from X a where nd=(select min(nd) from X where xm=a.xm)
      

  7.   

    update a
    set dm=1
    from x a,(select xm,min(nd) as nd from x group by xm) b
    where a.xm=b.xm and a.nd=b.nd
      

  8.   

    update x
    set dm = 1
    from x t where not exists(select 1 from x where xm = t.xm and nd < t.nd)update x
    set dm = 1
    from x t where nd = (select min(nd) from x where xm = t.xm)