【发布时间】:2019-02-03 10:13:36
【问题描述】:
我有两个 SQL 表:
matches (columns are hometeam, awayteam, id, gameweek)
teams (columns are teamcode, teamname)
matches.hometeam 和matches.awayteam 由与teams.teamcode 中的整数对应的整数组成。我试图让matches.hometeam 和matches.awayteam 更新为从teams.teamname 中的相应字符串中获取的字符串。如果这不可能,那么我需要按照说明创建一个新表。
我尝试了以下代码,但它在倒数第二行产生了语法错误(错误 1064 (42000))。我不知道为什么。
UPDATE matches
SET matches.hometeam = teams.teamname
FROM matches
INNER JOIN teams
ON (matches.hometeam = teams.teamcode);
【问题讨论】:
-
“matches.hometeam ...由整数组成”,“正在尝试获取matches.hometeam ...更新为字符串” -您不能将字符串放入整数列
-
你有外键或主键吗?您是否关心流程结束时的列名?你确定你应该做你正在尝试做的事吗?
标签: sql sql-update