Facebook
From Innocent Tapir, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 279
  1. select x.nr_line as Pierwsza, y.nr_line as druga from Course x, Course y,
  2. (
  3.         select top 1 A.course_id as startt, B.course_id as endd, A.stop_id, A._time as Atime, B._time as Btime, DATEDIFF(minute, A._time, B._time) as Diff from
  4.         (select course_id, stop_id, _time from TimeTable where TimeTable.course_id in
  5.                 (select course_id from TimeTable join Stops on TimeTable.stop_id = Stops.stop_id where Stops.stop_name = 'Arkadia') ) A
  6.                 join
  7.         (select course_id, stop_id, _time from TimeTable where TimeTable.course_id in
  8.                 (select course_id from TimeTable join Stops on TimeTable.stop_id = Stops.stop_id where Stops.stop_name = 'Sadyba') ) B
  9.                 on
  10.                 A.stop_id = B.stop_id AND A.course_id != B.course_id
  11.         where
  12.                 A._time < B._time
  13.         order by Diff
  14. ) z
  15. where
  16. x.course_id = z.startt AND y.course_id = z.endd