我必须编写一个非常有趣的查询,该查询可计算空值和带有值的行 [英] I have to write a very interesting query which calculates null values and rows with values

查看:53
本文介绍了我必须编写一个非常有趣的查询,该查询可计算空值和带有值的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我需要针对每个ID计算总数的数量和空值的数量 每个ID列都有很多行

I have a scenario where i need to calculate number of total values and number of null values against each ID each ID column have a number of rows

数据汇总

- ID     Col1     Col2    Col3    Col4    Col5    Col6
 - 132    12       0.5      0      Null     0.3     1.5
 - 132    Null     0.5      0      Null     0.3     1.5
 - 132    1        0.5      Null   Null     0.3     1.5
 - 132    2        0.5      0      0.3      1.5     Null  
 - 132    21       0.5      0      Null     0.3     1.5

 - 133    Null     Null     0      Null     Null    1.5
 - 133    12       0.5      0      Null     0.3     1.5
 - 133    Null     0.5      0      Null     0.3     1.5
 - 133    1        0.5      Null   Null     0.3     1.5
 - 133    2        0.5      0      0.3      1.5     Null  
 - 133    1        Null     0      Null     0.3     1.5
 - 133    Null     Null     0      Null     0.3     1.5

总结答案:我需要编写一个查询,该查询为我提供如下数据

Summarizing Answer :I need to write a query which gives me the data like following

- ID      NullCount    ValuesCount
 - 132      7               21    
 - 133      15              27    

我有一个部署快速帮助,将不胜感激.

I have a deployment quick help will be much appreciated.

谢谢

推荐答案

改编自 COUNT(ColX)仅计算NOT NULL值.当然,将所有六列的值相加就等于ValuesCount.
即使一行中的所有列都是NULLCOUNT(*)也会对所有行进行计数.将单元格总数乘以6,然后减去所有NOT NULL值以获得NULL计数.

COUNT(ColX) only counts NOT NULL values. Adding those for all six columns equals ValuesCount, of course.
COUNT(*) counts all rows, even if all columns within one row were NULL. Multiply by 6 for the total number of cells and then subtract all NOT NULL values to get the NULL count.

这篇关于我必须编写一个非常有趣的查询,该查询可计算空值和带有值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆