简体   繁体   English

使用来自另一个表的数据更新mysql表

[英]Updating mysql table with data from another table

I would like to update my table called nfl_roster with weekly scores that I have imported into another table (currently called week7_stats for the week I am doing it for now). 我想用导入到另一个表中的每周分数更新名为nfl_roster的表(当前我现在正在做的一周中,当前称为week7_stats)。 For example, in nfl_roster I have all of the players and then empty columns where I will input the scores as the week goes. 例如,在nfl_roster中,我拥有所有球员,然后有空栏,我将在一周中输入比分。 Here's an example of what it looks like: 这是一个看起来像的例子:

Name              week1_points week2_points ..... week7_points

A.J. Green            0             0                 0
Matthew Stafford      0             0                 0

Here is an example of the sheet where I have all of the scores for the players for week 7: 这是一张表格的示例,其中我拥有了第7周球员的所有得分:

name                week7_points
Matthew Stafford        3.590
Blake Bortles           2.894

So I need to update nfl_roster with weekly scores from another table (in this case week7_stats) and have it UPDATE the score in that week with the column in the weekly table. 因此,我需要使用另一个表(在本例中为week7_stats)的每周分数来更新nfl_roster,并使其具有每周表中的列来更新该周的分数。

更新nfl_roster加入week7_stats ON nfl_roster.Name = week7_stats.name SET nfl_roster.week7_points = week7_stats.week7_points

Try this: 尝试这个:

update nfl_roster 
set week7_points = (
     select week7_points 
     from week7_stats 
     where nfl_roster.Name = week7_points.name
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM