1

我有一个表“玩家”和“奖励”。我有一些重复的玩家条目,它们具有不同的 ID,但其他信息相同。

我正在尝试更新与第二个玩家条目相关的奖项,以便我最终可以删除重复项。

这显然不是最有效的查询,但它只需要运行一次,并且只有 10-15 个重复项。到目前为止,我有这个:

UPDATE aw
SET aw.player_id = map.id1
FROM awards as aw,
    (SELECT a.id as id1, b.id as id2
    FROM players a, players b
    WHERE a.first_name = b.first_name 
    AND a.last_name = b.last_name 
    AND a.id != b.id 
    AND a.team is not null 
    AND a.college is not null) as map
WHERE map.id2 = aw.player_id

这给了我一个未指定的语法错误,但如果我只用“Select aw.player_id, map.id1”替换前两行,它会返回一个包含预期值的两列表(所以列名和表引用都是正确的)。

我一定遗漏了一些明显的东西,但它是什么?

4

2 回答 2

3

UPDATE 语法中没有 FROM 。

您应该在 SET 之前在 UPDATE 部分定义表

UPDATE awards as aw,
  (SELECT a.id as id1, b.id as id2
  FROM players a, players b
  WHERE a.first_name = b.first_name 
  AND a.last_name = b.last_name 
  AND a.id != b.id 
  AND a.team is not null 
  AND a.college is not null) as map
SET aw.player_id = map.id1
WHERE map.id2 = aw.player_id
于 2012-04-05T21:15:35.920 回答
0

这在语法上应该是正确的。但是,我不确定它是否符合您的要求。首先测试暂存数据!

UPDATE
  players AS a 
INNER JOIN
  players AS b
ON
  a.first_name = b.first_name
  AND a.last_name = b.last_naem
  AND a.id != b.id
  AND a.team IS NOT NULL
  AND a.college IS NOT NULL
INNER JOIN
  awards AS aw
ON
  b.id = aw.player_id
SET
  aw.player_id = a.id
于 2012-04-05T21:15:43.703 回答