Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.38 KB | None | 0 0
  1. SELECT `s`.`subid`, `s`.`base` AS `basetype`, `s`.`code`, `s`.`name`, `s`.`state`, `s`.`period_restriction_type`, `s2`.`base_name`, `s`.`base` AS `sessions`,
  2.        GROUP_CONCAT(DISTINCT cl.classifier_id) AS `classifiers`, `s`.`type`,
  3.        CASE WHEN (s.period_restriction_type = 2 AND s.begin IS NULL) THEN s.begin_planned ELSE s.begin END AS `begin`,
  4.        CASE WHEN (s.period_restriction_type = 2 AND s.end IS NULL) THEN s.end_planned ELSE s.end END AS `end`,
  5.        `s`.`period`, `s`.`longtime`,`s`.`plan_users`, COUNT(DISTINCT st.mid) AS `students`
  6.        
  7. FROM `subjects` AS `s`
  8. LEFT JOIN `Students` AS `st` ON st.CID = s.subid
  9. LEFT JOIN `classifiers_links` AS `cl` ON s.subid = cl.item_id AND cl.type = 0
  10. LEFT JOIN (SELECT `subjects`.`subid` AS `base_id`, `subjects`.`name` AS `base_name` FROM `subjects`) AS `s2` ON s.base_id = s2.base_id
  11. INNER JOIN `Teachers` AS `teachers` ON s.subid = teachers.CID
  12. WHERE (teachers.MID = '140')
  13.  
  14. GROUP BY `s`.`subid`,
  15.          `s`.`base`,
  16.          `s`.`name`,
  17.          `s`.`code`,
  18.          `s`.`state`,
  19.          `s`.`period_restriction_type`,
  20.          `s`.`begin`,
  21.          `s`.`begin_planned`,
  22.          `s`.`end_planned`,
  23.          `s`.`end`,
  24.          `s`.`period`,
  25.          `s`.`price`,
  26.          `s`.`external_id`,
  27.          `s`.`type`,
  28.          `s`.`longtime`,
  29.          `s`.`base_id`,
  30.          `s`.`base`
  31. ORDER BY `name` ASC
  32. LIMIT 25;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement