2012-09-08 74 views
1

下面的例子停止在第一與一個錯誤消息加入在谷歌BigQuery中3個表

遇到「‘加入’」加入‘JOIN’在第13行,第4欄期待:‘)’

我是否在BigQuery中缺少一些明顯的多重連接?

SELECT type.CourseType AS CourseType, 
     SUM(joined.assign.StudentCount) AS StudentN 
FROM 
    (
    SELECT assign.StateCourseCode, 
      assign.StateCourseName, 
      assign.MatchType, 
      assign.Term, 
      assign.StudentCount 

    FROM [Assignment.AssignmentExtract5] AS assign 

    JOIN SELECT wgt.Term, 
       wgt.Weight 

    FROM [Crosswalk.TermWeights] AS wgt 
    ON wgt.Term = assign.Term 

) AS joined 

JOIN SELECT type.CourseCode, 
      type.CourseDescription, 
      type.CourseType, 
      type.CourseCategory 

FROM [Crosswalk.CourseTypeDescription] AS type 
    ON joined.assign.StateCourseCode = type.CourseCode 

GROUP BY CourseType 

回答

1

我認爲你只是缺少第13行

括號此:

JOIN SELECT wgt.Term, 
       wgt.Weight 

    FROM [Crosswalk.TermWeights] AS wgt 
    ON wgt.Term = assign.Term 

應該是:

JOIN (SELECT wgt.Term, 
       wgt.Weight 

    FROM [Crosswalk.TermWeights]) AS wgt 
    ON wgt.Term = assign.Term 

更多信息: https://developers.google.com/bigquery/docs/query-reference#multiplejoinsexample

僅供參考 - JOINs沒有我們想要的那麼快。我們正在努力提高性能。

2

謝謝瑞安,您的幫助非常感謝。對於任何可能感興趣的人來說,這是一個有效的查詢。

SELECT type.CourseCategory AS CourseCategory, 
     SUM(joined.assign.StudentCount) AS StudentN 
    FROM 
     (
     SELECT assign.StateCourseCode, 
       assign.StateCourseName, 
       assign.MatchType, 
       assign.Term, 
       assign.StudentCount 

     FROM [Assignment.AssignmentExtract5] AS assign 

     JOIN (SELECT Term, 
        Weight 

     FROM [Crosswalk.TermWeights]) AS wgt 
     ON wgt.Term = assign.Term 

    ) AS joined 

    JOIN (SELECT CourseCode, 
       CourseDescription, 
       CourseType, 
       CourseCategory 

     FROM [Crosswalk.CourseTypeDescription]) AS type 
    ON (joined.assign.StateCourseCode = type.CourseCode) 

    GROUP BY CourseCategory;