美文网首页
mysql 查询某个字段为空或不为空的数据

mysql 查询某个字段为空或不为空的数据

作者: 燃灯道童 | 来源:发表于2019-11-18 16:06 被阅读0次
建表语句中默认该字段为null

查询字段为空的数据。如下三条语句查询的结果各不相同。

select count(0) from tps_uw_detail where trim(coreContNo)=''; ###1736

select count(0) from  tps_uw_detail where coreContNo is null; ###735

select count(0) from  tps_uw_detail where (coreContNo is null or trim(coreContNo)='');##2471

='';就是存的空字符串;is null 就是默认的。

由于是后来新加的字段,默认为null,所以历史数据都为null。表中加上这个字段后,再落库的数据就是空字符串了。

根据自己的需求选用脚本,第三个是适合我的。

相关文章

网友评论

      本文标题:mysql 查询某个字段为空或不为空的数据

      本文链接:https://www.haomeiwen.com/subject/oddbictx.html