在Google bigquery中加入3个表格

时间:2012-09-08 18:33:02

标签: google-bigquery

以下示例在第一个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

2 个答案:

答案 0 :(得分:2)

谢谢Ryan,非常感谢您的帮助。对于任何可能感兴趣的人,这是一个有效的查询。

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;

答案 1 :(得分: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

仅供参考 - JOIN并不像我们想象的那么快。我们正致力于提高绩效。