SQL中使用where过滤空值
有三种方法:
- Where 列名 is not null
- Where 列名 != ‘null’
- Where 列名 <> ‘null’
牛客网例题:
https://www.nowcoder.com/practice/08c9846a423540319eea4be44e339e35?tpId=199&tqId=1971218&ru=%2Fta%2Fsql-quick-study&qru=%2Fta%2Fsql-quick-study%2Fquestion-ranking
select device_id,gender,age,university from user_profile where age is not null
Where in 和Not in
现在运营想要找到学校为北大、复旦和山大的同学进行调研,请你取出相关数据。
https://www.nowcoder.com/practice/0355033fc2244cdaa09b2bd6e794c762?tpId=199&tqId=1971219&ru=%2Fexam%2Fcompany&qru=%2Fta%2Fsql-quick-study%2Fquestion-ranking&sourceUrl=%2Fexam%2Fcompany
select device_id, gender, age ,university ,gpa from user_profile where university="北京大学" or university="复旦大学" or university="山东大学"
# 使用not in
select device_id, gender, age ,university ,gpa from user_profile where university not in ('浙江大学')