【问题标题】:Big Query filtering null rows of Custom query creating tableBig Query 过滤自定义查询创建表的空行
【发布时间】:2019-12-04 07:31:09
【问题描述】:

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

这是我目前的查询:

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"

这是我的查询结果:

【问题讨论】:

    标签: google-bigquery analytics firebase-analytics


    【解决方案1】:

    以下是 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)
    

    【讨论】:

      【解决方案2】:

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

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

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

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

      希望有帮助!

      【讨论】:

      • 以下是我的查询选择 (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不为空).string_value 作为用户 FROM some_data_set 其中 event_name="ConfirmOrderBtn" 和 event_date 介于 '20191110' 和 '_*' 和 app_info.id = "app_id"
      • 感谢您的欢迎 :) 。我还在查询中添加了不为空的检查,但它仍然返回空记录
      • 谢谢,我已编辑您的问题以添加到此查询中并相应地更新了我的答案!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-17
      • 2020-10-06
      • 2020-09-04
      • 2012-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多