【发布时间】:2020-10-28 04:40:59
【问题描述】:
-
Progress表有progressId、lessonId和uniqueId -
TestResults表有progressId -
TestResults表 现在有lessonId和uniqueId
这条 SQL 语句 foreach progrssId in TestResults 将从 Progress 得到 lessonId 和 uniqueId:
select progressId,
(select lessonId from Progress p where p.progressId = TestResults.progressId) as lessonId,
(select uniqueId from Progress p where p.progressId = TestResults.progressId) as uniqueId
from TestResults
where progressId is not null;
现在我想更新 lessonId 和uniqueId 中的TestResults 表foreach 关联progressId。我需要foreach的想法。我不知道如何在 SQL 中做到这一点。
【问题讨论】:
-
正如重复问题的答案所示,您可以直接将选择的结果插入到表格中。但是,在这种特殊情况下,我真的不明白您为什么要这样做,因为您可以通过连接检索关联的值。
-
您确定要在表 TestResults 中插入新行吗?也许您想使用 Progress 中的列值更新现有行?
-
我正在尝试删除这些旧列
-
是的,更新不插入
-
感谢任何帮助或提示。非常感谢