Big Query" WITH statement"导致语法错误" WITH trip AS( - 语法无效)

时间:2017-12-14 16:52:56

标签: python sql common-table-expression google-cloud-datalab

我的问题是关于在Google数据实验室中尝试此操作,但不断返回语法错误

  File "<ipython-input-26-03f6ca240d16>", line 4
    WITH trips AS (
             ^
SyntaxError: invalid syntax
import google.datalab.bigquery as bq
import pandas as pd
import numpy as np
import shutil

%bq query -n taxiquery
WITH trips AS (
  SELECT EXTRACT (DAYOFYEAR from pickup_datetime) AS daynumber 
  FROM `bigquery-public-data.new_york.tlc_yellow_trips_*`
  where _TABLE_SUFFIX = @YEAR
)
SELECT daynumber, COUNT(1) AS numtrips FROM trips
GROUP BY daynumber ORDER BY daynumber

query_parameters = [
  {
    'name': 'YEAR',
    'parameterType': {'type': 'STRING'},
    'parameterValue': {'value': 2015}
  }
]
trips = taxiquery.execute(query_params=query_parameters).result().to_dataframe()
trips[:5]

1 个答案:

答案 0 :(得分:1)

将查询定义输出到自己的单元格中。 %bq query...是一种多线魔术语法,需要单独存在于单元格中。