SQl使用OR运算符选择空值

时间:2016-05-07 09:34:58

标签: sql

我已离开加入exam_admission_student表格我想只选择那些status = 1Exam_admission_stutend表中不包含的值

select ps.name,
       ps.uni_registration,
       eas.enrolled_in_exam,
       ps.id,
       ps.father_name,
       ps.student_cnic,
       sps.id,
       sc.id 
from profile_student ps  
left join assignment_student_program_session sps on sps.std_id=ps.id  
left join assignment_session_program sp on sp.id=sps.program_session_comb_id  
left join assignment_student_class sc on sc.std_prog_session_combid=sps.id
left join exam_admission_student eas on eas.std_class_combid=sc.id  
where  sps.status=1 
and sps.program_session_comb_id=1008 
and sps.inst_id=9 
and sc.part='part1'
and eas.status is null 
or eas.status=1

1 个答案:

答案 0 :(得分:1)

除非我遗漏了某些内容,否则只需添加一个括号:(假设状态不可为空)

select ps.name,
       ps.uni_registration,
       eas.enrolled_in_exam,
       ps.id,
       ps.father_name,
       ps.student_cnic,
       sps.id,
       sc.id 
from profile_student ps  
left join assignment_student_program_session sps on sps.std_id=ps.id  
left join assignment_session_program sp on sp.id=sps.program_session_comb_id  
left join assignment_student_class sc on sc.std_prog_session_combid=sps.id
left join exam_admission_student eas on eas.std_class_combid=sc.id  
where  sps.status=1 
and sps.program_session_comb_id=1008 
and sps.inst_id=9 
and sc.part='part1'
and (eas.status is null or eas.status=1)