update a set a.cc = b.bb
from prdt a 
join (
Select aa,sum(bb) as bb from prdt group by aa
) b on a.aa = b.aa 
where IsNull(a.cc,0) = 0

解决方案 »

  1.   


    update a set a.cc = b.bb
    from prdt a 
    join (
    Select aa,sum(bb) as bb from prdt group by aa
    ) b on a.aa = b.aa 
    where a.cc is null
      

  2.   

    update tablename b set bb=a.bb from (select sum(bb) bb from tablename where aa=b.aa group by aa) a where b.cc=''
      

  3.   

    update tablename b set bb=a.bb from (select aa,sum(bb) bb from tablename  group by aa having aa=b.aa) a where b.cc=''
      

  4.   

    好象txlicenhe(马可) 把楼主的意思理解错了,同意letsflytogether(恨!不能拥有天下所有的财富,然后平分)的解答。 :)
      

  5.   

    update tablename b set bb=a.bb 
    from (select sum(bb) bb,aa from tablename where aa=b.aa group by aa) a 
    where b.cc is null and tablename .aa=a.aa
      

  6.   

    表prdt有三个字段
    String aa;
    int    bb;
    int    cc;
    现在要将aa相同的所以记录的bb的值相加,把总数放在相同aa且cc为空的记录中。请问如何实现?
    数据例如:
    aa    bb      cc
    ss    1       
    ss    3       4
    vv    55      
    vv    2       6
    vv    6       8
    结果为:
    aa    bb      cc
    ss    4       
    ss    3       4
    vv    63       
    vv    2       6
    vv    6       8   create table prdt(aa varchar(100),bb int,cc int)
    insert into prdt select  'ss'   , 1       ,null
    insert into prdt select  'ss',    3,       4
    insert into prdt select  'vv',    55,null      
    insert into prdt select  'vv',    2,       6
    insert into prdt select  'vv',    6,       8
    goupdate a
    set a.bb=a.bb+b.sums
    from prdt as a join (select aa,sum(bb) as sums 
    from prdt 
    where  cc is not null 
    group by aa) as b 
    on a.aa=b.aa
    where a.cc is null
      

  7.   

    create table test_table (aa varchar(100),bb int,cc int)
    insert into test_table select  'ss'   , 1       ,null
    insert into test_table select  'ss',    3,       4
    insert into test_table select  'vv',    55, null      
    insert into test_table select  'vv',    2,       6
    insert into test_table select  'vv',    6,       8update test_table
    set bb=b.bb
    from (select aa as df,sum(bb) bb from test_table group by aa) b
    where aa=b.df and cc is  null
      

  8.   


    update a set a.bb = b.bb
    from test_table a 
    join (Select aa,sum(bb) as bb from test_table group by aa) b 
    on a.aa = b.aa 
    where a.cc is null
      

  9.   

    感谢 txlicenhe(马可) !!!