当我包含'WHERE'时,Google BigQuery不会运行'GROUP BY'子句到我的查询

时间:2015-07-27 10:05:03

标签: google-bigquery

每当我在Google BigQuery上汇总数据时运行(选择,发件人,限制)查询,我的查询会显示一个表格(它有效),但每次我添加任何其他“子句”,例如“WHERE” &安培; 'GROUP BY' - 始终显示错误。 例如:

SELECT
  cigarette_use,
  AVG(weight_pounds) baby_weight,
  AVG(mother_age) mother_age,
  STDDEV( weight_pounds) baby_weight_stdev,
FROM
  [publicdata:samples.natality]
LIMIT
  1000
WHERE
  year=2003
  AND state='OH'
GROUP BY
  cigarette_use;

对于上面的查询,显示了此错误 -

"Error: Encountered " "WHERE" "WHERE "" at line 10, column 1. Was expecting: <EOF>
Job ID: decent-courage-101120:job_Ts2AJAeI8SijokiKCnV5joh5VQg"

当我从查询中删除'WHERE'子句时,即

WHERE
  year=2003
  AND state='OH'

显示此错误 -

"Error: Encountered " "GROUP" "GROUP "" at line 10, column 1. Was expecting: <EOF>
Job ID: decent-courage-101120:job_Hq_Ux9x-pBGwcwaG7wJ8KlthUys"

有人可以告诉我我做错了什么以及如何在Google BigQuery上运行上述简单查询而不会遇到错误?

谢谢。

1 个答案:

答案 0 :(得分:5)

您需要在查询的最后使用LIMIT

SELECT cigarette_use,
       AVG(weight_pounds) baby_weight,
       AVG(mother_age) mother_age,
       STDDEV(weight_pounds) baby_weight_stdev,
FROM [publicdata:samples.natality]
WHERE YEAR=2003
  AND STATE='OH'
GROUP BY cigarette_use
LIMIT 1000;