怎么查询一行当中为NUL或为空的字段数量啊 求大神赐教啊?
数据库数据如下:
id name scores sex age email address
1 zhangsan NULL NULL 12 大地
如何查询出为空或为NULL的总数量(结果为3)?
数据库数据如下:
id name scores sex age email address
1 zhangsan NULL NULL 12 大地
如何查询出为空或为NULL的总数量(结果为3)?
SELECT (6-IF(name>0,1,0)-IF(scores>0,1,0)-IF(sex>0,1,0)-IF(age>0,1,0)-IF(email>0,1,0)-IF(address>0,1,0)) FROM yourTable GROUP BY id
*
from tab1
where
case when scores is null then 1 else 0 end
+
case when sex is null then 1 else 0 end
+
case when age is null then 1 else 0 end
+
case when nullif(email,'')='' then 1 else 0 end
+
case when nullif(address,'')='' then 1 else 0 end
=3
;=3为条件只显示有3列满足条件的数据,可自定义