我正在尝试将两个表连接在一起,一个表有两个我想要的标识符。
select stations.id, stations.name, count (rentals.startstation_id) as station_starts, count (rentals.endstation_id) as station_ends
from ny.station as stations
Left Join ny.rental as rentals on stations.id = rentals.startstation_id
Left Join ny.rental as rentals on station.id = rentals.endstation_id
group by 1,2
然而,ny.rental表非常大,当我运行此查询时,我的SQL Workbench / J崩溃了。站台很小。
构建此查询的最佳方法是什么?