Tuesday, July 19, 2022

[FIXED] How do I incorporate FLOAT in my query when calculating the average of a set of values when my result could be a FLOAT and not INTEGER to avoid error

Issue

I am trying to determine the average of a set of values from a table but I am getting an error.

I entered the query below to determine the average riderships from 2013 - 2016 but got this error - No matching signature for operator / for argument types: STRUCT<INT64, INT64>, INT64. Supported signatures: FLOAT.

SELECT
station_name,
ridership_2013,
ridership_2014,
ridership_2015,
ridership_2016,
(ridership_2013 + ridership_2014 + ridership_2015, ridership_2016) / 4 AS Average_ridership

FROM bigquery-public-data.new_york_subway.subway_ridership_2013_present;

Solution

You simply has a typo! try below

SELECT
station_name,
ridership_2013,
ridership_2014,
ridership_2015,
ridership_2016,
(ridership_2013 + ridership_2014 + ridership_2015 + ridership_2016) / 4 AS Average_ridership
FROM bigquery-public-data.new_york_subway.subway_ridership_2013_present;    

as you can see - the typowas a comma instead of plus sign in ridership_2015, ridership_2016



Answered By - Mikhail Berlyant
Answer Checked By - Terry (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.