在大查询中的特定列中查找所有具有空值的行

时间:2019-04-16 21:48:39

标签: google-cloud-platform google-bigquery

是否可以改善以下内容?我需要计算特定列中具有NULL个值的所有行。

SELECT
  SUM(IF(column1 IS NULL, 1, 0)) AS column1, 
  SUM(IF(column2 IS NULL, 1, 0)) AS column2
FROM 
  `dataset.table`;

1 个答案:

答案 0 :(得分:3)

其中一个选项:

   
#standardSQL
SELECT
  COUNTIF(column1 IS NULL) AS column1,
  COUNTIF(column2 IS NULL) AS column2
FROM `project.dataset.table`   

或者(只是为您提供一些选择):

#standardSQL
SELECT
  COUNT(1) - COUNT(column1) AS column1,
  COUNT(1) - COUNT(column2) AS column2
FROM `project.dataset.table`