Big Query 过滤自定义查询的空行创建 table

Big Query filtering null rows of Custom query creating table

我正在尝试在大查询中查询我的数据并希望避免空记录但不断获取它们。

到目前为止,这是我的查询:

select 
(SELECT x.value FROM UNNEST(user_properties) x 
WHERE x.key='restaurantName' 
and x.value is not null).string_value as restaurantName ,
(SELECT x.value FROM UNNEST(user_properties) x 
WHERE x.key='restaurantId' and x.value is not null).string_value as 
restaurantID , 
(SELECT x.value FROM UNNEST(user_properties) x 
WHERE x.key='user_id' and x.value is not null).string_value as user 
FROM some_data_set where event_name="ConfirmOrderBtn" and event_date between 
'20191110' and '_*' and app_info.id = "app_id"

这是我的查询结果:

欢迎,添加 WHERE 子句(例如 WHERE restaurant_name IS NOT NULL 将阻止 'restaurant_name' 中具有空值的行出现在您的结果中。

更新:现在我可以看到您的查询非常复杂并且使用子查询 - 如果您想从最终结果中过滤我们的空值,在这种情况下,您可以使用 HAVING,例如: HAVING restaurant_name 不为空`

HAVING 在您的子查询之后执行,因此它作为 link 结果的最终过滤器 - 请注意,您仍然需要为返回 HAVING 子句之前的所有数据付费.

HAVING 上的文档 link: https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#having-clause

希望对您有所帮助!

以下适用于 BigQuery 标准 SQL

#standardSQL
SELECT * FROM (
  SELECT 
    (SELECT x.value 
      FROM UNNEST(user_properties) x 
      WHERE x.key='restaurantName' 
      AND x.value IS NOT NULL
    ).string_value AS restaurantName ,
    (SELECT x.value 
      FROM UNNEST(user_properties) x 
      WHERE x.key='restaurantId' 
      AND x.value IS NOT NULL
    ).string_value AS restaurantID , 
    (SELECT x.value 
      FROM UNNEST(user_properties) x 
      WHERE x.key='user_id' 
      AND x.value IS NOT NULL
     ).string_value AS user 
  FROM `project.dataset.some_data_set` 
  WHERE event_name="ConfirmOrderBtn" 
  AND event_date BETWEEN '20191110' AND '_*' 
  AND app_info.id = "app_id" 
)
WHERE NOT (restaurantName IS NULL OR restaurantID IS NULL OR user IS NULL)