Otsi Detailne otsing

Ei leidnud ühtegi toimuvat kursust süsteemist.

SELECT DISTINCT c.*, o.name AS organization_name, COUNT(cr.id) AS reservations_count FROM courses AS c LEFT JOIN organizations AS o ON o.id = c.org_id LEFT JOIN course_reservations AS cr ON cr.course_id = c.id AND cr.is_active > 0 WHERE c.is_active > 0 AND (c.status = 'P' OR c.status = 'R') AND ((c.start_date <= '2017-05-27' AND c.end_date >= '2017-05-27') OR c.start_date >= '2017-05-27') GROUP BY c.id ORDER BY c.start_date