mysql - 根据第二个表中输入的值更新 MYSQL 表

标签 mysql updating

我有一个包含体育得分和排名的数据库。我有一个像这样的积分榜...

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/

相关文章:

mysql - 与 Mariadb 10.2 相比,Mysql 5.5 中的查询非常慢

mysql选择最近的,按来源限制

html - CSS 不随变化更新

php - Laravel DB::RAW() NOT IN 不工作

mysql从linux转储到windows

c# - 什么是 '' Size''参数大小单位,在Set parameter Method中?

php - 更新 PHP CMS 网站以完全支持 unicode/utf8

Android,为什么更新我的图像时启动器图标和其他图像永远不会改变?

java - CompletableFuture 中的静态集合更新#runAsync

python - 使用 loc 更新数据框 python pandas