null和空字符串对于查询where条件语句的影响

在数据库中我们进行数据处理的过程中,对于null值或者空字符串的情况对于这种数据我们进行计算平均值以及查询过程中如何进行对于这类数据的处理呢?

  step1:建表:create table a(id int not null,number varchar(20) default null)

  step2:插入使用的数据:insert into a values(1,'123'),(2,'123'),(3,'123'),(4,null),(5,'');

显示结果:

 

 

 第一点:is not null和<> null之间的区别

select * from  a where number is not null;   ----可以计算出非空的所有行(显示空字符串)

 

 

 

select * from  a where number <> null;  ----无法进行查询

 

 

第二点:!=‘’的使用

select * from  a where number !='';    -----会将空字符串和null值全部剔除

 

posted @ 2021-12-24 15:21  天行者_sky  阅读(65)  评论(0编辑  收藏  举报