August 18, 2022 at 8:30 pm
This appears to work, but there may be a more efficient method. Is 60 minutes and 1 second considered > 60 minutes? I assumed so, so I used datediff 3600 seconds rather than 60 minutes. It doesn't change the results, but it could.
SELECT d.station_name, SUM(d.StationCount) AS number_reachable_stations
FROM (
SELECT a.code, a.station_name, c.StationCount
FROM dbo.train_st AS a
OUTER APPLY ( SELECT COUNT (station_name) AS StationCount
FROM dbo.train_st AS b
WHERE b.code = a.code
AND b.arrival > a.departure
AND DATEDIFF(ss,a.departure, b.arrival) <=3600) AS c
) AS d
GROUP BY d.station_name
ORDER BY number_reachable_stations DESC, d.station_name
August 18, 2022 at 10:47 pm
thank you so much
August 19, 2022 at 7:19 am
This was removed by the editor as SPAM
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply