当我的结果可能是 FLOAT 而不是 INTEGER 时,如何在计算一组值的平均值时将 FLOAT 合并到我的查询中以避免错误
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
我正在尝试从 table 中确定一组值的平均值,但出现错误。
我在下面输入查询以确定 2013 年至 2016 年的平均乘客量,但出现此错误 - 运算符/参数类型没有匹配的签名:STRUCT, INT64。支持的签名: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;
使用 CAST 将数据类型更改为 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;
你只是打错了字!试试下面
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;
如您所见 - 打字是逗号而不是加号 ridership_2015, ridership_2016
我正在尝试从 table 中确定一组值的平均值,但出现错误。
我在下面输入查询以确定 2013 年至 2016 年的平均乘客量,但出现此错误 - 运算符/参数类型没有匹配的签名:STRUCT
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;
使用 CAST 将数据类型更改为 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;
你只是打错了字!试试下面
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;
如您所见 - 打字是逗号而不是加号 ridership_2015, ridership_2016