有表结构类似于
a(no,class,money)
数据
1,1,10
1,null,2
2,1,2
2,1,5
……
请问如何用一条语句更新表a
使得class为空的更新为同一个no号的非空值?
谢谢各位打侠

解决方案 »

  1.   

    Update T Set class = (Select Max(class) From A Where [no] = T.[no]) From A T
      

  2.   

    update a set class=case when class is null then (select top 1 class from [Table] where no=a.no and class is not null ) else class end from [Table] a
      

  3.   

    少了條件Update T Set class = (Select Max(class) From A Where [no] = T.[no]) From A T Where class Is Null
      

  4.   

    chuifengde(树上的鸟儿) ,谢谢,我怎么给你分阿
      

  5.   

    update a set class=(select top 1 class from a as t where t.no=a.no and t.class is not null) where a.class is null
      

  6.   

    create table a(no int,class int,money int)insert into a
    select 1,1,10    union all
    select 1,null,2  union all
    select 2,1,2     union all
    select 2,1,5update a
    set class=isnull(class,no) select * from adrop table a
      

  7.   

    update a set class=no
    where class=null
      

  8.   

    update a set class=no from a
    where class=null