update tt2 set score=case usetype 
when 'A' then score+bb.A 
when 'C' then score+bb.C
when 'D' then score+bb.D
when 'L' then score+bb.L 
when 'P' then score+bb.P
else score end
from tt1 a where tt2.userid=a.userid

解决方案 »

  1.   

    update tt2 set Score=Score+ ss
    from tt1 
    (select userid, 'a' as UseType , a as ssfrom ttl union  
     select userid, 'c' as UseType , c as ss from ttl union  
     select userid, 'd' as UseType , d as ss from ttl union  
     select userid, 'l' as UseType , l as ss from ttl union  
     select userid, 'p' as UseType , p as ss from ttl ) a
    where  a.userid=tt2.userid and a.UseType =tt2.UseType
      

  2.   

    update tt2 set score=case usetype 
    when 'A' then score+bb.A 
    when 'C' then score+bb.C
    when 'D' then score+bb.D
    when 'L' then score+bb.L 
    when 'P' then score+bb.P
    else score end
    from tt1 bb where tt2.userid=bb.userid
      

  3.   

    tt1表结构问题。 A    C    D    L     P
    是字段名UserID的值吗?
    还是 A    C    D    L     P都是字段名?
      

  4.   

    select * from tt1
    select * from tt2
    select tt2.UserID,tt2.UserType,
    case UserType
    when 'A' then tt2.Score + tt1.A
    when 'C' then tt2.Score + tt1.C
    when 'D' then tt2.Score + tt1.D
    when 'L' then tt2.Score + tt1.L
    when 'P' then tt2.Score + tt1.P
    else
    tt2.Score
    end
    ,tt2.ScoreTime
    from tt2,tt1
      

  5.   

    select tt2.UserID,tt2.UserType,
    case UserType
    when 'A' then tt2.Score + tt1.A
    when 'C' then tt2.Score + tt1.C
    when 'D' then tt2.Score + tt1.D
    when 'L' then tt2.Score + tt1.L
    when 'P' then tt2.Score + tt1.P
    else
    tt2.Score
    end as Score
    ,tt2.ScoreTime
    from tt2,tt1
      

  6.   

    CrazyFor(蚂蚁):
    A、C 、D、L、P都是字段UseType的值,是一种标识?比如说D表示下载,P表示发布…
    字段Score是表示各操作的得分总值,会不断的累加。
      

  7.   

    表tt1其实是一个查询出来的结果集。
    UserID   A    C    D    L     P
    admin    40   30   3    22    44
    aa       ……
    bb       ……
    ……
    读出每个UserID的值后再往表tt2累加。
      

  8.   

    两个表的UserID需要一一对应吗?
      

  9.   

    pengdali(大力) 
    A、C 、D、L、P不是字段名。