我有两个表 T_SUBJECTS (subject_id, date_of_birth) 和 T_ADMISSIONS (visit_id, subject_id, date_of_admission, age)。我想用入学时的年龄更新年龄列。我编写了更新查询并得到“单行子查询返回多行”。我理解错误,但认为 where exists 子句可以解决问题。下面是查询。
UPDATE
t_admissions
SET
t_admissions.age =
(
SELECT
TRUNC(months_between(t_admissions.date_of_admission,
t_subjects.date_of_birth)/12)
FROM
t_admissions,
t_subjects
WHERE
t_admissions.subject_id = t_subjects.subject_id
AND t_admissions.age = 0
AND t_admissions.date_of_admission IS NOT NULL
AND t_subjects.date_of_birth IS NOT NULL
)
WHERE
EXISTS
(
SELECT
1
FROM
t_admissions, t_subjects
WHERE
t_admissions.subject_id = t_subjects.subject_id
);