【发布时间】:2016-09-20 15:17:00
【问题描述】:
我正在尝试在 BigQuery 中加入三个表;表 1 有一个事件的记录(即每一行是一个记录),表 2 有第二个事件的记录,表 3 有类别名称。
我想按类别和设备平台生成一个包含表 1 和表 2 计数的最终表。但是,每次我运行它时,我都会收到一条错误消息,提示 joined.t3.category 不是连接中任一表的字段。
这是我当前的代码:
Select count(distinct joined.t1.Id) as t1_events, count(distinct t2.Id) as t2_events, joined.t1.Origin as platform, joined.t3.category as category
from
(
SELECT
Id,
Origin,
CatId
FROM [testing.table_1] as t1
JOIN (SELECT category,
CategoryID
FROM [testing.table_3]) as t3
on t1.CatId = t3.CategoryID
) AS joined
JOIN (SELECT Id,
CategoryId
FROM [testing.table_2]) as t2
ON (joined.t1.CatId = t2.CategoryId)
Group by platform,category;
作为参考,下面是表 1 和表 2 之间的一个更简单的连接,效果很好:
Select count(distinct t1.Id) as t1_event, count(distinct t2.Id) as t2_events, t1.Origin as platform
from testing.table_1 as t1
JOIN testing.table_2 as t2
on t1.CatId = t2.CategoryId
Group by platform;
【问题讨论】:
标签: sql google-bigquery