我正在尝试在 mysql 中运行此查询
UPDATE studentassessment sa SET sa.issubmitted=FALSE WHERE
sa.studentassessmentid <>
(SELECT studentassessmentid FROM studentassessment sa1 WHERE
sa.StudentId=sa1.StudentId
AND sa.AssessmentPeriodId=sa1.AssessmentPeriodId
ORDER BY sa1.studentassessmentid DESC LIMIT 0, 1)
AND sa.studentid=568;
这给了我这个错误
您不能在 FROM 子句中指定目标表 'sa' 进行更新
我发现了这类问题的数量,但它们特定于他们被问到的查询,所以对我没有多大帮助,从 SO 我试图改变这样的查询的答案之一
UPDATE studentassessment sa SET issubmitted=FALSE WHERE
sa.studentassessmentid <>
(
SELECT studentassessmentid FROM
(
SELECT studentassessmentid FROM studentassessment sa1 WHERE
sa.StudentId=sa1.StudentId
AND sa.AssessmentPeriodId=sa1.AssessmentPeriodId
ORDER BY sa1.studentassessmentid DESC LIMIT 0, 1
) AS T
)
AND sa.studentid=568;
然后我开始收到这个错误
“where 子句”中的未知列“sa.StudentId”
有什么帮助吗?
编辑
这也不起作用
UPDATE studentassessment sa
INNER JOIN
(SELECT studentassessmentid FROM studentassessment sa1 WHERE
sa.StudentId=sa1.StudentId
AND sa.AssessmentPeriodId=sa1.AssessmentPeriodId
ORDER BY sa1.studentassessmentid DESC LIMIT 0, 1) T
ON sa.studentassessmentid<>T.StudentAssessmentId
SET sa.issubmitted=0
WHERE sa.studentid=568;