1 つの値をサブクエリから得られた多くの値と比較する方法
if(select COUNT(si.s_id)--==========>1 check if student has 4 passed courses
from students.student_study_subjects,students.study_info si,students.subjects,admins.years
where students.student_study_subjects.degree>=students.subjects.min_degree
AND students.student_study_subjects.subj_code=students.subjects.subj_code
AND si.d_id=students.student_study_subjects.d_id
AND si.year=admins.years.year_num
AND si.year=(select max(admins.years.year_num)-1 from admins.years)
group by si.d_id,si.year)=4
begin
insert into study_info
(s_id,year,dept_id,s_state,group_num)
select students.study_info.s_id,max(admins.years.year_num),students.study_info.dept_id,'new',students.study_info.group_num+1
from students.study_info,admins.years
group by students.study_info.s_id,students.study_info.dept_id,students.study_info.group_num
end
一般に、このサブクエリが4に等しい値を返す場合、テーブルにいくつかの値を挿入したい