2014-09-12 70 views
5

我一直在試圖解決這個錯誤小時,沒有任何運氣,它對我已經沒有問題,運行了幾個星期,但突然我看到這個錯誤的查詢:的BigQuery JOIN錯誤

Error: ON clause must be AND of = comparisons of one field name from each table, with all field names prefixed with table name.

查詢的格式如下:

SELECT S.av AS av, S.dm AS dm, t, gn 
FROM [dataset.cTable] 
JOIN EACH (SELECT id, av, dm FROM [dataset.sTable]) AS S ON S.id = sid 
AND (t == 'type1' OR t == 'type2') GROUP EACH BY av, dm, t, gn; 

任何幫助將不勝感激。

+0

ON子句的AND部分未指定連接條件。將其更改爲WHERE。 – antlersoft 2014-09-12 22:17:48

回答

2

(t == 'type1' OR t == 'type2')子句不是連接條件,它是where條件。如果您將您的查詢更改爲:

SELECT S.av AS av, S.dm AS dm, C.t, C.gn 
FROM [dataset.cTable] C 
JOIN EACH (SELECT id, av, dm FROM [dataset.sTable]) AS S ON S.id = sid 
WHERE (C.t == 'type1' OR C.t == 'type2') GROUP EACH BY S.av, S.dm, C.t, C.gn; 

它應該工作。

+0

感謝將AND更改爲WHERE修復它。 – 2014-09-12 22:58:16

0

假定在別名中添加可以解決問題。我也並不認爲子查詢是必要的:

SELECT S.av AS av, S.dm AS dm, c.t, c.gn 
FROM [dataset.cTable] as c JOIN EACH 
    [dataset.sTable] AS S 
    ON S.id = c.sid 
WHERE c.t in ('type1', 'type2') 
GROUP EACH BY av, dm, t, gn; 

each可能不是必要的,但我不是過於熟悉谷歌的BigQuery。

+0

剛剛嘗試過,沒有運氣。我猜它是一個BigQuery問題......感謝您的建議 – 2014-09-12 22:34:52