UPDATE persons
SET persons.EN_FAMILY = 'Test'
WHERE persons.STCODE IN
(SELECT students.PERSONS_STCODE AS STCODE
FROM students
WHERE @Counter > 0
AND students.ID NOT IN
(SELECT sel_lesson.ST_ID
FROM sel_lesson
WHERE sel_lesson.YEAR = @CurrenYear
AND sel_lesson.TERM = @CurrentTerm
GROUP BY sel_lesson.ST_ID)
AND students.STATUS IN('1','14')
);
答案 0 :(得分:1)
尝试使用内部联接
UPDATE persons
INNER JOIN (SELECT students.PERSONS_STCODE AS STCODE
FROM students
WHERE @Counter > 0
AND students.ID NOT IN
(SELECT sel_lesson.ST_ID
FROM sel_lesson
WHERE sel_lesson.YEAR = @CurrenYear
AND sel_lesson.TERM = @CurrentTerm
GROUP BY sel_lesson.ST_ID)
AND students.STATUS IN('1','14') ) T on t.STCODE = persons.STCODE
SET persons.EN_FAMILY = 'Test'