Home > Software engineering >  How do I incorporate FLOAT in my query when calculating the average of a set of values when my resul
How do I incorporate FLOAT in my query when calculating the average of a set of values when my resul

Time:03-31

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;

CodePudding user response:

Use CAST to change the data types to INT64.

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

FROM bigquery-public-data.new_york_subway.subway_ridership_2013_present;

CodePudding user response:

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

  • Related