在两个条件下加入一张大表而没有超时

时间:2017-06-05 17:05:54

标签: postgresql

我正在尝试将两个表连接在一起,一个表有两个我想要的标识符。

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崩溃了。站台很小。

构建此查询的最佳方法是什么?

0 个答案:

没有答案