MySQL获取选课情况

SELECT
  * 
FROM
  (
  SELECT
    t1.DATA AS timeid,
    t2.type AS timeType,
    t2.weekday AS weekday,
    t2.`start`,
    t2.
  END,
  t3.reid,
  t3.userid AS userid 
FROM
  ims_rooit_class_data AS t1
  LEFT JOIN ims_rooit_class_timelist AS t2 ON t1.DATA = t2.timeid
  LEFT JOIN ims_rooit_class_records AS t3 ON t1.reid = t3.reid 
WHERE
  t1.type = 'timerange' 
  AND t1.formid = '1' 
ORDER BY
  timeType ASC,
  FIELD(
    t2.weekday,
    'Monday',
    'Tuesday',
    'Wednesday',
    'Thursday',
    'Friday',
    'Saturday',
    'Sunday' 
  ),
  t2.`start` 
  ) AS t_res1
  LEFT JOIN (
  SELECT
    reid,
    SUBSTRING_INDEX( newdata, ',', 1 ) AS f1,
    SUBSTRING_INDEX(
      SUBSTRING_INDEX( newdata, ',', 2 ),
      ',',- 1 
    ) AS f2,
    SUBSTRING_INDEX(
      SUBSTRING_INDEX( newdata, ',', 3 ),
      ',',- 1 
    ) AS f3 
  FROM
    (
    SELECT
      formid,
      reid,
      GROUP_CONCAT( DATA ) AS newdata 
    FROM
      (
      SELECT
        t_data.reid AS reid,
        t_data.`data`,
        t_data.type,
        t_field.title AS title,
        t_field.formid AS formid 
      FROM
        ims_rooit_class_data AS t_data
        LEFT JOIN ims_rooit_class_fields AS t_field ON t_data.fieldid = t_field.fieldid 
      WHERE
        t_field.type != 'timerange' 
        AND t_field.formid = '1' 
      ) AS t_join 
    GROUP BY
      reid 
    ) AS t_join2 
  ) AS t_res2 ON t_res1.reid = t_res2.reid

 

请我喝杯咖啡吧~

支付宝
微信