我必须编写一个非常有趣的查询,该查询可计算空值和带有值的行 [英] I have to write a very interesting query which calculates null values and rows with values
本文介绍了我必须编写一个非常有趣的查询,该查询可计算空值和带有值的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一种情况,我需要针对每个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)
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屋!
查看全文