mysql 为什么我总是在BigQuery中得到语法错误,谁来帮我弄明白谢谢

kcugc4gi  于 2023-05-16  发布在  Mysql
关注(0)|答案(1)|浏览(149)

我似乎不知道我做错了什么。这是我得到的错误
参数类型的operator =没有匹配的签名:字符串,INT64.支持的签名:ANY = ANY at [15:8]
enter image description here

SELECT
  station_id,
  name,
  number_of_rides AS number_of_rides_starting_at_station
FROM 
  (
    SELECT 
      start_station_id,
      COUNT(*) number_of_rides
    FROM bigquery-public-data.new_york_citibike.citibike_trips
    GROUP BY 
      start_station_id
  ) subquery
  INNER JOIN bigquery-public-data.new_york_citibike.citibike_stations 
    ON station_id = subquery.start_station_id
ORDER BY
  number_of_rides DESC
lf5gs5x2

lf5gs5x21#

消息“No matching signature for operator = for argument types:字符串,INT64.支持的签名:ANY = ANY”表示station_id和start_station_id列具有不同的数据类型,一个是字符串,另一个是整数。
若要修复此问题,请将其中一列强制转换为另一列的数据类型。你需要弄清楚哪个是整数,哪个是字符串。例如

SELECT data_type
FROM `bigquery-public-data.new_york_citibike.INFORMATION_SCHEMA.COLUMNS`
WHERE table_name = 'citibike_stations' AND column_name = 'station_id'

我建议将整数列转换为字符串(所有整数都可以是字符串,但不能反过来)

SELECT
       station_id
     , name
     , number_of_rides AS number_of_rides_starting_at_station
FROM (
  SELECT start_station_id, COUNT(*) number_of_rides
  FROM bigquery-public-data.new_york_citibike.citibike_trips
  GROUP BY start_station_id
) subquery
INNER JOIN bigquery-public-data.new_york_citibike.citibike_stations
    ON CAST(station_id AS STRING) = subquery.start_station_id
ORDER BY number_of_rides DESC

当然,这是一个猜测,它可能是相反的方式,即:

INNER JOIN bigquery-public-data.new_york_citibike.citibike_stations
    ON station_id = CAST(subquery.start_station_id AS STRING)

nb:可以使用safe_cast()进行转换,但不需要将integer转换为string

相关问题