sql中null值。只有`is null`能查到`null`值记录。`null`既不属于`是`也不属于`非`(即`score = ‘1‘`与`score != ‘1‘`均查不到`null`记录)

1.先上结论

只有is null能查到null值记录。null既不属于也不属于(即score = '1'score != '1'均查不到null记录),同理以下均查不到null值。

序号条件
1=!=<>
2><>>=<=
3innot in
4likenot like
5betweennot between
6is not null

2.测试

  • 基于mysql8、oracle

2.1.建表造数据

-- 建表
drop table if exists student;
create table student
(
    id    int default null,
    score int default null
);
-- 造数据5条,其中1条null
insert into student (id, score) values (1, 1);
insert into student (id, score) values (2, 2);
insert into student (id, score) values (3, 3);
insert into student (id, score) values (4, 4);
insert into student (id, score) values (5, null);

2.2.查询

-- 只有 is null 能查到null值记录
select '1',count(*) from student where score = '1' or score != '1'
union all
select '2',count(*) from student where score > '1' or score <= '1'
union all
select '3',count(*) from student where score in ('1') or score not in ('1')
union all
select '4',count(*) from student where score like '1%' or score not like '1%'
union all
select '5',count(*) from student where score between '1' and '1' or score not between '1' and '1'
union all
select '6',count(*) from student where score is not null
union all
select '7',count(*) from student where score is null
  • 查询结果
    在这里插入图片描述

posted on   小石头小祖宗  阅读(9)  评论(0编辑  收藏  举报  

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示