0

如何将一个值与子查询产生的多个值进行比较

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,我想在表中插入一些值

4

1 回答 1

0

你可以试试这个:

  1. 将 存储output(count)在一个变量中。
  2. 检查变量是否等于 4。
  3. 如果是,那么您可以运行插入查询
于 2012-04-30T07:31:31.933 回答