Using a CASE statement to change the value of a new BigQuery column based finding one specific entry inside a PARTITION

前端 未结 2 636
孤城傲影
孤城傲影 2021-01-28 23:54

I trying to write some case statements which might change the value of all entries in the call if a particular condition is satisfied INSIDE the partition. Here is the specific

相关标签:
2条回答
  • 2021-01-29 00:12

    It is entirely possible that this could be done with a smart usage of analytics functions, but my SQL-fu isn't up to it. That said, it sounds like what you want is achievable with a simple JOIN statement. Let's say your current query is called Q (you could even save this as a view to make it easier).

    Run

    SELECT t1.*, t2.has_some_property
    FROM Q AS t1
    LEFT OUTER JOIN (
      SELECT unique_visit_id, 1 as has_some_property
      FROM Q 
      WHERE (REGEXP_MATCH(lagged, ...) 
          AND REGEXP_MATCH(hits.page.pagePath))
      GROUP BY unique_visit_id
      ) AS t2
    ON t1.unique_visit_id == t2.unique_visit_id
    
    0 讨论(0)
  • 2021-01-29 00:19

    If you are looking for avoiding joins, you can use an aggregated function with Over. something like:

    Max(If((Your Condition here),Your value here, Null)) Over( Partition By Your_Partition)
    

    the window functions used to had some performance issues that should have been improved recently. My experience with BQ drives me to prefer Jordan's Join suggestion. But hey, its a fun riddle...

    0 讨论(0)
提交回复
热议问题