日期:2014-05-19  浏览次数:20713 次

!!!急求一SQL语句!!!!
足球比赛表:Tmatch
字段:match_id     (主键)
            home_id       主队ID
            away_id       客队ID

进球表:Tlineup(每个进球一条记录)
字段:line_id   (主键)
          match_id   比赛ID
          club_id     进球球队ID(不知道主?客队)
          play_id     进球人
          goal_time   进球时间
          score           进球时比分
要更新score字段,现在是空的
他记录球员进球前双方比分状态(格式     2:1)
进球球员所属球队得分放前面
比如甲,乙两队此时比分是3:1
乙队再进一球,此时score为2:3

怎么写SQL,不知道表达清楚没有!


------解决方案--------------------
不清楚
比分从哪里获得?
------解决方案--------------------
没有表达清楚,写一些数据出来表达会清楚一些
------解决方案--------------------
update Tlineup set score=(case when home_id=club_id then rtrim(cast(left(score,charindex( '- ',score)-1) as int)+1)+right(score,len(score)-charindex( '- ',score)+1)
else left(score,charindex( '- ',score))+rtrim(cast(right(score,len(score)-charindex( '- ',score)) as int)+1) end)
from Tmatch a,Tlineup b where a.match_id=b.match_id
and line_id=1000---测试用1000