Joining 3 tables in Google bigquery

梦想的初衷 提交于 2020-01-16 08:23:27

问题


The example below stops at the first JOIN with an error message

Encountered " "JOIN" "JOIN "" at line 13, column 4. Was expecting: ")"

Am I missing something obvious with multiple joins in 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:


I think you're just missing a parenthesis on line 13.

This:

   JOIN SELECT wgt.Term,
               wgt.Weight 

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

Should be:

   JOIN (SELECT wgt.Term,
               wgt.Weight 

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

More info: https://developers.google.com/bigquery/docs/query-reference#multiplejoinsexample

FYI - JOINs are not as fast as we'd like yet. We're working on improving the performance.




回答2:


Thanks Ryan, your help was much appreciated. For anyone who might be interested, here is a query that worked.

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;


来源:https://stackoverflow.com/questions/12333401/joining-3-tables-in-google-bigquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!