我的查询无法运行,我认为查询是正确的,有人知道我做错了什么吗?

huangapple go评论47阅读模式
英文:

my query won't run, and I think the query is correct, anyone knows what I did wrong?

问题

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

这个查询的一部分在BigQuery上被标记为语法错误(start_station_name,),我按照我的教程中的方式精确复制了它。但它没有返回结果。

英文:
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, end_station, usertype
ORDER BY num_trips DESC LIMIT 10

This part of the query was underlined as a SYNTAX error on the big query (start_station_name,) I copied it the exact way my instructor did on a course. But it didn't return a result.

答案1

得分: 1

修复了你的查询:

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 usertype, start_station_name, end_station_name ORDER BY num_trips DESC LIMIT 10

已经修复了usertype后面的逗号问题,也修复了int64后面的括号问题,以及修正了GROUP BY中的列名。查询现在可以运行并生成结果。

英文:

fixed the query for you:

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

there was a missing comma after usertype. there was missing parenthesis after int64. the group by had the wrong column names.

query runs and produces results.

huangapple
  • 本文由 发表于 2023年2月14日 19:55:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75447475.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定