【发布时间】:2013-05-10 18:57:18
【问题描述】:
我正在尝试运行加入 2 个大型数据集的查询,并且在查询执行错误期间遇到了超出的资源。我读过在使用 Join Each 和 Group Each 时有一些解决方法,但不是那些解决方法。
SELECT
year(users.firstseen) as first_year,
month(users.firstseen) as first_month,
DATEDIFF(orders.timestamp,users.firstseen) as days_elapsed,
count(orders.user_key) as count_orders
FROM
[project.orders] as orders
JOIN EACH
[project.users] AS users
ON
orders.user_key = users.user_key
WHERE orders.store = 'ios'
GROUP EACH BY 1,2,3
编辑:以下工作:
SELECT
year(users.firstseen) as firstyear,
month(users.firstseen) as firstmonth,
DATEDIFF(orders.timestamp, users.firstseen) as days_elapsed,
COUNT(users.firstseen) AS count_orders FROM [project.orders] as orders
JOIN EACH( SELECT user_key, firstseen FROM [project.users]
WHERE store_key = 'ios') as users ON orders.user_key = users.user_key
GROUP BY firstyear, firstmonth, days_elapsed
ORDER BY firstyear, firstmonth, days_elapsed
【问题讨论】:
-
这最终工作 SELECT year(users.firstseen) as firstyear, month(users.firstseen) as firstmonth, DATEDIFF(orders.timestamp, users.firstseen) as days_elapsed, COUNT(users.firstseen) AS count_orders FROM [project.orders] as orders JOIN EACH( SELECT user_key, firstseen FROM [project.users] WHERE store_key = 'ios') as users ON orders.user_key = users.user_key GROUP BY firstyear, firstmonth, days_elapsed ORDER BY firstyear , firstmonth, days_elapsed
标签: sql google-bigquery