我有2张桌子,上面有一些列车信息。
是否有可能找出在同一州内有多少班次?
答案 0 :(得分:0)
...不确定
Select count(*) NbrDepInCA
from departures d join trainStation s
on s.station_code = d.origin_station_code
Where s.State = 'CA'
并且,正如@Katteract建议的那样,计算所有州(至少有一次出发)的数量
Select s.State, count(*) NbrDepInState
from departures d join trainStation s
on s.station_code = d.origin_station_code
Group by s.State
答案 1 :(得分:0)
在PostgreSQL
中你可以使用类似这样的SQL:
SELECT COUNT(1) AS count FROM departures d
JOIN trainStation t1 ON t1.station_code = d.origin_station_code
JOIN trainStation t2 ON t2.station_code = d.destination_station_code
WHERE t1.state = t2.state