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
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
解决方案 »
- 请问:SQL2000使用中,未能为数据库 'DBName' 中的对象 'Table' 分配空间,因为文件组 'PRIMARY'已满。原因是什么,如何解决,谢谢!
- 如何按起止时间及类型生成日期分组表
- SQL 按ID及列内容自动生成序号排序问题
- SQL2005如何設置用戶連接人數
- 再問一個 :iif( instr([Param]![Com],[svr_Mast]![Com]>0,yes,No)=yes如何轉化為SQL
- 能否将二套源码的数据库合到一数据库里
- 因解决“无法进入SQL Server服务器”问题,请leimin大虾进来领分(二)。
- 写储存过程时怎样判断insert语句是否成功执行呢?
- sql server 支不支持recordcount
- 我想给大侠加分怎么办?另外怎么升级ODBC的SQLSRV32.DLL
- 急!小弟想做个图书馆管理系统不知怎么下手,希望大家能进来聊聊,介绍几本好书源码也好而且还想加上网络功能.
- 一个奇怪的Sql Server的问题,欢迎大家来讨论!!(来者有分)
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
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
是字段名UserID的值吗?
还是 A C D L P都是字段名?
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
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
A、C 、D、L、P都是字段UseType的值,是一种标识?比如说D表示下载,P表示发布…
字段Score是表示各操作的得分总值,会不断的累加。
UserID A C D L P
admin 40 30 3 22 44
aa ……
bb ……
……
读出每个UserID的值后再往表tt2累加。
A、C 、D、L、P不是字段名。