【问题标题】:BigQuery COALESCE() with SELECT subquery带有 SELECT 子查询的 BigQuery COALESCE()
【发布时间】:2018-02-27 20:22:58
【问题描述】:

我收到错误:

Correlated subqueries that reference other tables are not supported unless they can be de-correlated, such as by transforming them into an efficient JOIN

关于以下查询

(SELECT DISTINCT video_id, 
                   COALESCE(custom_id, 
                             (SELECT custom_id FROM `test2.channel_map` b 
                              WHERE a.channel_id = b.channel_id LIMIT 1), 
                                'Default')
 FROM `test2.revenue` a)

我实际上是在尝试用查找表中的另一个 custom_id 替换 null custom_ids。有没有更好的方法可以让 BigQuery 接受?

【问题讨论】:

    标签: google-bigquery


    【解决方案1】:

    只需使用常规的 LEFT JOIN - 如下所示

    SELECT DISTINCT video_id, 
      COALESCE(
        a.custom_id, 
        b.custom_id, 
        'Default'
      )
    FROM `test2.revenue` a
    LEFT JOIN `test2.channel_map` b
    ON a.channel_id = b.channel_id   
    

    【讨论】:

      猜你喜欢
      • 2013-03-19
      • 2017-04-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-02
      • 2015-02-02
      • 2017-07-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多