我有一个包含体育得分和排名的数据库。我有一个像这样的积分榜...
Team Overall Record Conference Record
Team1 5-0 2-0
Team2 4-1 1-1
Team3 3-2 0-2
我有一个游戏结果表...
Team Result1 Result2 Result3 Result4 Result5 Result6
Team1 W W W W W
Team2 W L W W W
Team3 W L L W W
现在,当我在下一场比赛的 Result6 中添加“W”时,有没有办法让它在积分榜上将 Team1 记录更新为 6-0,或者如果它是“L”,则将其更改为 5-1 ?
最佳答案
你的表结构很糟糕,我的报价也很糟糕!
SET @teamname := 'team1';
SELECT @myres := concat(Result1,Result2,Result3,Result4,Result5,Result6) -- and other columns
FROM results
WHERE team = @teamname;
UPDATE sports_score
SET overal = concat(
length(@myres)-length(replace(@myres,'W',''))
,'-',
length(@myres)-length(replace(@myres,'L',''))
)
WHERE team = @teamname ;
关于mysql - 根据第二个表中输入的值更新 MYSQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42378724/