【问题标题】:resources exceeded in bigquery sqlbigquery sql 中超出的资源
【发布时间】:2020-03-17 02:54:37
【问题描述】:

我有一个删除重复项的简单 cte 查询。

with cte as (
   select     Agent_SK
    , Listing_Agent_License_Number
    , Listing_Agent_Name
    , Listing_Agent_Address
    , Listing_Agent_Phone
    , Listing_Agent_Email
    , Office_Name
    , Office_Address
    , Office_Phone
    , Office_Email
        , Update_Timestamp
        , ROW_NUMBER() OVER (PARTITION BY Listing_Agent_Name
                                        , Listing_Agent_Address
                                        , Listing_Agent_Phone
                                        , Listing_Agent_Email
                             ORDER BY Update_Timestamp DESC) AS rn
   from `mother-216719.VALUATION.MLS`
   where Agent_SK is not null
) select
    Agent_SK
    , Listing_Agent_License_Number
    , Listing_Agent_Name
    , Listing_Agent_Address
    , Listing_Agent_Phone
    , Listing_Agent_Email
    , Office_Name
    , Office_Address
    , Office_Phone
    , Office_Email
    , Update_Timestamp
from cte
where rn = 1;

此查询提供了超出的资源。我认为这与row_number() 功能有关。我该如何解决这个问题?

【问题讨论】:

    标签: sql google-bigquery


    【解决方案1】:

    下面是 BigQuery 标准 SQL,应该可以解决问题

    #standardSQL
    WITH cte AS (
      SELECT     
        Agent_SK
        , Listing_Agent_License_Number
        , Listing_Agent_Name
        , Listing_Agent_Address
        , Listing_Agent_Phone
        , Listing_Agent_Email
        , Office_Name
        , Office_Address
        , Office_Phone
        , Office_Email
        , Update_Timestamp
      FROM `mother-216719.VALUATION.MLS`
      WHERE Agent_SK IS NOT NULL
    ) 
    SELECT AS VALUE ARRAY_AGG(t ORDER BY Update_Timestamp DESC LIMIT 1)[OFFSET(0)] 
    FROM cte t
    GROUP BY     
      Listing_Agent_Name
      , Listing_Agent_Address
      , Listing_Agent_Phone
      , Listing_Agent_Email
    

    【讨论】:

    • 我需要了解有关 ARRAY_AGG 的更多信息。那是你第二次用那个救了我。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多