Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT DISTINCT ON (t._id) t._id,
  2.                    t._date
  3. FROM
  4.   (SELECT schedule_lesson.id AS _id,
  5.           latest_scehedule_lesson.date_ AS _date
  6.    FROM schedule_lesson
  7.    JOIN studytimecall ON schedule_lesson.studycall_id = studytimecall.id
  8.    JOIN
  9.      (SELECT schedule_lesson.id AS id,
  10.              schedule_lesson.discipline_group_id AS discipline_group_id,
  11.              schedule_lesson.date AS date_,
  12.              studytimecall.begin AS begin_
  13.       FROM schedule_lesson
  14.       JOIN studytimecall ON schedule_lesson.studycall_id = studytimecall.id) AS latest_schedule_lesson ON schedule_lesson.discipline_group_id=latest_schedule_lesson.discipline_group_id
  15.    AND schedule_lesson.id <> latest_schedule_lesson.id
  16.    AND (schedule_lesson.date < latest_schedule_lesson.date_
  17.         OR (schedule_lesson.date = latest_schedule_lesson.date_
  18.             AND studytimecall.begin < latest_schedule_lesson.begin_))
  19.    ORDER BY schedule_lesson.id,
  20.             latest_schedule_lesson.date_ DESC, latest_schedule_lesson.begin_ DESC) AS t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement