简体   繁体   中英

I am having issues with a SQL query

I was following along with my instructor on the google data analytics course, below is the code I wrote and I keep getting an error

SELECT  
  usertype,
  CONCAT(start_station_name, " to ", end_station_name) AS route,
  COUNT(*) as num_trips,
  ROUND(AVG(cast(tripduration as int64)/60).2)
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

The error is Cannot access field 2 on a value with type FLOAT64 at [5:45]

You have a typo in your round function, it is written as ROUND(AVG(cast(tripduration as int64)/60).2) and it is supposed to be ROUND(AVG(cast(tripduration as int64)/60), 2) .

The dot represents that you are trying to access the field "2" of the AVG(cast(tripduration as int64)/60) value, which is a FLOAT64, therefore creating the error "Cannot access field 2 on a value with type FLOAT64 at [5:45]".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM