text: 
  SELECT
    lectures.id, lectures.name, lectures.course, lectures.stamp,
    users.name as creator,
    COUNT(tracking.id) as views
  
  FROM
    lectures
      JOIN courses ON courses.id = lectures.course AND courses.deleted = 0
      LEFT JOIN users ON users.id = lectures.creator
      LEFT JOIN users as viewers ON viewers.type = 'student' AND viewers.blocked = 0 AND viewers.deleted = 0
      LEFT JOIN tracking ON tracking.id = viewers.id AND tracking.path = CONCAT(CONCAT('lectures/', CONCAT(lectures.type, 's/')), lectures.id)
  
  WHERE
    lectures.type = '$d[type]' AND lectures.deleted = 0
  
  GROUP BY
    lectures.id
    
  ORDER BY
    lectures.course,
    lectures.nu,
    lectures.name,
    lectures.creator,
    lectures.id;