[英]BigQuery unexpected keyword
I'm just getting started with Google BigQuery, and have run into issues with my very first query.我刚刚开始使用 Google BigQuery,并且在我的第一个查询中遇到了问题。 I'm trying to get a list of Stack Overflow posts since and including 2015-01-01 which have one of several tags.
我正在尝试获取自 2015 年 1 月 1 日以来(包括 2015 年 1 月 1 日)的 Stack Overflow 帖子列表,这些帖子具有多个标签之一。 Below is my first pass at the query:
以下是我在查询中的第一遍:
#standardSQL
SELECT
title,
body,
answer_count,
creation_date,
tags,
view_count
FROM
`bigquery-public-data.stackoverflow.posts_questions` limit 10
WHERE
creation_date >= "2015-01-01" AND tags HAVING "terraform" OR "chef" OR "puppet" OR "ansible"
The BigQuery validator is showing the following error message: BigQuery 验证器显示以下错误消息:
Error : Syntax error: Unexpected keyword WHERE at [14:1]错误:语法错误:[14:1] 处的意外关键字 WHERE
You have a few syntax errors, namely the limit 10
in the wrong place, and using the HAVING
keyword incorrectly. 您有一些语法错误,即错误位置的
limit 10
和错误使用HAVING
关键字。 I'd also use native timestamp
instead of comparing strings: 我还将使用本机
timestamp
而不是比较字符串:
#standardSQL
SELECT
title,
body,
answer_count,
creation_date,
tags,
view_count
FROM
`bigquery-public-data.stackoverflow.posts_questions`
WHERE
creation_date >= TIMESTAMP('2015-01-01')
AND tags IN ('terraform',
'chef',
'puppet',
'ansible')
LIMIT
10
There are a few issues here, but hopefully this will help: 这里有一些问题,但是希望这会有所帮助:
With that said this query might be what you want: 这样说来,此查询可能就是您想要的:
#standardSQL
SELECT
title,
body,
answer_count,
creation_date,
tags,
view_count
FROM `bigquery-public-data.stackoverflow.posts_questions`
WHERE creation_date >= "2015-01-01" AND
EXISTS (
SELECT 1 FROM UNNEST(SPLIT(tags, "|")) AS tag
WHERE tag IN ("terraform", "chef", "puppet", "ansible")
)
LIMIT 10;
Note that I needed to use SPLIT
with the tags
column because the tags are separated by the pipe character. 请注意,我需要在
tags
列中使用SPLIT
,因为标签由竖线字符分隔。 Since you get a terabyte of querying for free, try to make the most of it by getting all the results at once rather than using the LIMIT, too. 由于您可以免费获得TB级的查询,因此请尝试一次获取所有结果而不是使用LIMIT来充分利用它。
SELECT SELECT
usertype, CONCAT(start_station_name, " to ",end_station_name) AS route, COUNT(*) as num_trips, ROUND(AVG(cast(tripduration as int64)/60),2) AS duration FROM bigquery-public-data.new_york_citibike.citibike_trips
GROUP BY start_station_name, end_station_name,usertype, ORDER BY num_trips DESC LIMIT 10用户类型,CONCAT(start_station_name, " to ",end_station_name) AS route, COUNT(*) as num_trips, ROUND(AVG(cast(tripduration as int64)/60),2) AS duration FROM
bigquery-public-data.new_york_citibike.citibike_trips
GROUP BY start_station_name,end_station_name,usertype,ORDER BY num_trips DESC LIMIT 10
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.