我正在遵循脚本,但我的计数函数仍然导致错误

i was following a script but my count function still resulted in an error

提问人:Marshlyn Walters 提问时间:11/12/2023 最后编辑:Adrian MaxwellMarshlyn Walters 更新时间:11/12/2023 访问量:17

问:

为什么我的查询没有在 SQL 中使用 COUNT 函数运行?COUNT(*) 作为 num_trips,

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 
google-bigquery的 计数

评论


答:

1赞 Adrian Maxwell 11/12/2023 #1

当某些内容“未运行”时,通常会出现错误消息。在以后的问题中,请包括完整的错误消息。这是我认为可能出错的地方。

AS route”和“COUNT(*)”之间缺少逗号"

出于多种原因,包括这个原因,我一直更喜欢“逗号优先”的 SQL 格式方法,就像这样。几乎不可能避免以这种方式包含正确的逗号,例如:

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;