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

问题描述 投票:0回答:1

为什么我的查询没有使用 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 count
1个回答
0
投票

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

AS 路线”和“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;
© www.soinside.com 2019 - 2024. All rights reserved.