select Query

  • thank you

    • This topic was modified 1 year, 8 months ago by  fri.
  • 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
  • thank you so much

  • 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