LEFT OUTER JOIN Error creating a subquery on bigquery

ぃ、小莉子 提交于 2021-02-18 19:29:32

问题


I'm trying to eval MAL, WAL and DAU from a event table on my bq...

I create a query find DAU and with him find WAU and MAU, but it does not work, i received this error:

LEFT OUTER JOIN cannot be used without a condition that is an equality of fields from both sides of the join.

It's my query

WITH dau AS (
  SELECT 
      date, 
      COUNT(DISTINCT(events.device_id)) as DAU_explorer         
  FROM `workspace.event_table` as events
  GROUP BY 1
)

SELECT  
  date, 
  dau, 
  (SELECT 
      COUNT(DISTINCT(device_id))  
     FROM `workspace.event_table` as events
     WHERE events.date BETWEEN DATE_ADD(dau.date, INTERVAL -30 DAY)  AND dau.date
     ) AS mau,
  (SELECT 
      COUNT(DISTINCT(device_id)) as DAU_explorer  
    FROM `workspace.event_table` as events
    WHERE events.date BETWEEN DATE_ADD(dau.date, INTERVAL -7 DAY)  AND dau.date
       ) AS wau
FROM dau

Where is my error? Is not possible run subqueries like this on bq?


回答1:


Try this instead:

WITH data AS (
  SELECT DATE(creation_date) date, owner_user_id device_id
  FROM `bigquery-public-data.stackoverflow.posts_questions` 
  WHERE EXTRACT(YEAR FROM creation_date)=2017
)

#standardSQL
SELECT DATE_SUB(date, INTERVAL i DAY) date_grp
 , COUNT(DISTINCT IF(i<31,device_id,null)) unique_30_day_users
 , COUNT(DISTINCT IF(i<8,device_id,null)) unique_7_day_users
FROM `data`, UNNEST(GENERATE_ARRAY(1, 30)) i
GROUP BY 1
ORDER BY date_grp
LIMIT 100
OFFSET 30

And if you are looking for a more efficient solution, try approximate results.



来源:https://stackoverflow.com/questions/56136871/left-outer-join-error-creating-a-subquery-on-bigquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!