为什么我总是在 BigQuery 中收到语法错误。有人,请帮助我理解。谢谢

问题描述 投票:0回答:1

我似乎无法确定我做错了什么。这是我得到的错误

operator = 参数类型没有匹配的签名:STRING, 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
sql mysql google-bigquery syntax-error operators
1个回答
0
投票

消息“No matching signature for operator = for argument types: STRING, INT64. Supported signature: 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() 进行转换,但整数到字符串不需要它

© www.soinside.com 2019 - 2024. All rights reserved.