我希望能够在bigquery中加入多个表。加入两个是非常微不足道的。
SELECT
t1.field1 AS field1,
t2.field2 AS field2,
t1.field3 AS field3
FROM [datasetName.tableA] t1
JOIN [datasetName.tableB] t2
ON t1.somefield = t2.anotherfield
但是如果我想加入三张或更多桌子怎么办?我可以这样做吗
SELECT
t1.field1 AS field1,
t2.field2 AS field2,
t1.field3 AS field3,
t3.field4 as field4
FROM [datasetName.tableA] t1
JOIN [datasetName.tableB] t2
JOIN [datasetName.tableC] t3
ON t1.somefield = t2.anotherfield AND t1.somefield=t3.yetanotherfield
我已经尝试过了,但它没有用。我想我需要做一些像
这样的事情SELECT
t12.field1 as field1,
t12.field2 as field2,
t3.field3 as field3,
FROM
(SELECT
t1.field1 AS field1,
t2.field2 AS field2,
t1.field3 AS field3
FROM [datasetName.tableA] t1
JOIN [datasetName.tableB] t2
ON t1.somefield = t2.anotherfield) t12
JOIN
[datasetName.tableC] t3
ON t12.field1 = t3.field1
但有没有更简单的方法来实现这一目标?
谢谢, 布拉德
答案 0 :(得分:9)
我认为您正在寻找类似下面的内容
Restangular.one('company').one('manager', managerId).get(params)
答案 1 :(得分:1)
您还可以在标准SQL中使用USING(field)
表示法。实际上,这只是@ mikhail-berlyant答案的糖。文件here
#standardSQL
SELECT
t1.field1 AS field1,
t2.field2 AS field2,
t1.field3 AS field3
FROM `datasetName.tableA` t1
JOIN `datasetName.tableB` t2 USING(commonfield_AB)
JOIN `datasetName.tableC` t3 USING(commonfield_AC)