根据另外两个 table 值更新 table 列
Update table column based on two other table values
我需要根据另外 2 个 table 的数据更新我的 table 之一中的列。
所以我希望 table questionObjectives 中的列 isAvailable 根据 2 个条件设置为 1,这就是我所拥有的:
UPDATE
dbo.questObjectives
SET
isAvailable = 1
FROM
dbo.questObjectives qo
INNER JOIN
dbo.dungeonList dl
ON
qo.questID = dl.questID
WHERE dl.dungeonType = 17
AND qo.objectiveID IN(SELECT objectiveID FROM gameMissions)
所以要翻译,isAvailable 应该设置为 1,如果:
the linked dungeonList type is 17
the questionObjectives objectiveID is in the table gameMissions
所以我认为我的逻辑是正确的,但我一直收到这个错误:
'invalid column name isAvailable.'
但它就在那里。它在 questionObjectives table 中,所以我不确定我做错了什么。
有什么想法吗?
谢谢!
这是你想要的吗?
update qo
set qo.isavailable = 1
from questObjectives qo
inner join dungeonList dl on qo.questID = dl.questID
where
dl.dungeonList = 17
and exists (select 1 from gameMissions gm where gm.objectiveID = qo.objectiveID)
您查询的主要问题是您在 update
和 from
子句中都有目标 table questObjectives
;你应该只在 from
子句中使用一次,然后在 update
子句中引用别名。
我也将 in
条件重写为与 exists
相关的子查询 - 逻辑是相同的,但这可能表现更好。
我需要根据另外 2 个 table 的数据更新我的 table 之一中的列。
所以我希望 table questionObjectives 中的列 isAvailable 根据 2 个条件设置为 1,这就是我所拥有的:
UPDATE
dbo.questObjectives
SET
isAvailable = 1
FROM
dbo.questObjectives qo
INNER JOIN
dbo.dungeonList dl
ON
qo.questID = dl.questID
WHERE dl.dungeonType = 17
AND qo.objectiveID IN(SELECT objectiveID FROM gameMissions)
所以要翻译,isAvailable 应该设置为 1,如果:
the linked dungeonList type is 17
the questionObjectives objectiveID is in the table gameMissions
所以我认为我的逻辑是正确的,但我一直收到这个错误:
'invalid column name isAvailable.'
但它就在那里。它在 questionObjectives table 中,所以我不确定我做错了什么。
有什么想法吗?
谢谢!
这是你想要的吗?
update qo
set qo.isavailable = 1
from questObjectives qo
inner join dungeonList dl on qo.questID = dl.questID
where
dl.dungeonList = 17
and exists (select 1 from gameMissions gm where gm.objectiveID = qo.objectiveID)
您查询的主要问题是您在 update
和 from
子句中都有目标 table questObjectives
;你应该只在 from
子句中使用一次,然后在 update
子句中引用别名。
我也将 in
条件重写为与 exists
相关的子查询 - 逻辑是相同的,但这可能表现更好。