You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用别名与子查询时遭遇Unrecognized Name Error的技术问询

问题原因与修正方案

你的SQL触发Unrecognized Name Error,是因为**trips别名仅在子查询内部生效**,外部的INNER JOIN语句无法识别这个别名。子查询已经被命名为station_num_trips,关联条件里得用这个别名来访问子查询输出的start_station_id字段。

修正后的SQL语句

SELECT 
    stations.station_id,
    stations.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` AS trips 
     GROUP BY
         start_station_id) AS station_num_trips
INNER JOIN
    `bigquery-public-data.new_york_citibike.citibike_stations` AS stations
      ON station_num_trips.start_station_id = stations.station_id 
ORDER BY 
    number_of_rides DESC

关键修改点

  • 把关联条件里的 trips.start_station_id 替换成 station_num_trips.start_station_id,让外部查询能正确引用子查询的字段。

内容的提问来源于stack exchange,提问作者Shaakira Calnick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 17:42:03