我有以下查询,我想要排除'否'的值。我想要包含N / A,Yes和null。 '否','是','N / A'和'null'是此列中的唯一值。当我运行我的查询时,它不返回空值,但它确实返回'N / A'和'是'。
select s.schoolid as "School Code",
sch.name as "School Name",
s.student_number as "Student Id",
s.lastfirst as "Name",
s.gender as "Gender",
s.grade_level as "Grade",
s.street as "Street",
s.city as "City",
s.state as "State",
s.zip as "Zip",
s.home_phone as "Home Phone"
from u_students u
left join students s on u.studentsdcid = s.dcid
left join schools sch on s.schoolid = sch.school_number
where s.grade_level in ('11','12')
and s.enroll_status = '0'
and U.Scs_Perm_Share_Military Not like 'No'
order by sch.name asc ;
答案 0 :(得分:0)
如果SELECT语句要测试除其他值之外的空值,则它必须包含IS NULL子句。另外,正如其他人所说,你应该使用左连接条件,而不是在where子句中放置过滤器:
select s.schoolid as "School Code",
sch.name as "School Name",
s.student_number as "Student Id",
s.lastfirst as "Name",
s.gender as "Gender",
s.grade_level as "Grade",
s.street as "Street",
s.city as "City",
s.state as "State",
s.zip as "Zip",
s.home_phone as "Home Phone"
from u_students u
left join students s on u.studentsdcid = s.dcid
and s.grade_level in ('11','12')
and s.enroll_status = '0'
left join schools sch on s.schoolid = sch.school_number
where (U.Scs_Perm_Share_Military IS NULL
OR
U.Scs_Perm_Share_Military <> 'No'
)
order by sch.name asc ;