现有数据如上。要使所有以ID为个体的tot_cred的值为对应的所有credits的总和,怎么办?例如:00128,tot_cred=7

解决方案 »

  1.   

    update
      a
    set
      credits=b.credits
    from
       tb a,
       (select tot_cred,sum(credits) as credits group by tot_cred)b
    where
      a.tot_cred=b.tot_cred
      

  2.   

    update TB
    set TB.credits = T.credits
    from TB
    inner join (select ID,sum(credits)as credits from TB)T on T.id = TB.id
      

  3.   

     group by ID 忘记加了。Godupdate TB
    set TB.credits = T.credits
    from TB
    inner join (select ID,sum(credits)as credits from TB group by ID)T on T.id = TB.id
      

  4.   

    update a
    set credits=b.credits
    from  tb a,
    (select tot_cred,sum(credits) as 'credits' from a group by tot_cred)b
    where a.tot_cred=b.tot_cred
      

  5.   


    update  a
    set  credits=(select sum(credits) as credits WHERE tot_cred=a.tot_cred AND ID=a.ID)
    from   tb a
      

  6.   

    update a
    set credits=b.credits
    from  tb a,
    (select tot_cred,sum(credits) as [credits] from a group by tot_cred)b
    where a.tot_cred=b.tot_cred