BigQuery -获取由另一个列分组的空值的百分比



我有一个像

这样的表
tbody> <<tr>
store_codecountry_code时间戳
FR1234567890
123FR1234567890
456GB1234567890
789GB1234567890

一种方法只使用avg():

SELECT country_code, 
AVG(case when store_code IS NULL then 1.0 else 0 end) as null_ratio
FROM table
GROUP BY country_code;

如果要计数并除以总数,则使用COUNTIF():

SELECT country_code, 
COUNTIF(store_code IS NULL) * 1.0 / COUNT(*) as null_ratio
FROM table
GROUP BY country_code;

最新更新