Advertisement
jeniferfleurant

Club attendance

Jul 17th, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.56 KB | None | 0 0
  1. USE caris_db;
  2. SET  @start_date = '2018-10-01';
  3. SET @end_date = '2019-06-30';
  4. SELECT
  5.     lookup_hospital.name AS club_hospital,
  6.     patient_code,
  7.     lookup_club_type.name AS club_type,
  8.     club.name,
  9.     IF(tm.id_patient IS NOT NULL,
  10.         'female',
  11.         lookup_gender.name) AS gender,
  12.     COALESCE(tracking_infant.dob, tm.dob) AS dob,
  13.     date AS date_session,
  14.     COALESCE(tracking_infant.id_patient,
  15.             tm.id_patient) AS id_patient,
  16.     COALESCE(tracking_infant.first_name,
  17.             tm.first_name) AS first_name,
  18.     COALESCE(tracking_infant.last_name, tm.last_name) AS last_name,
  19.     CONCAT(MONTH(date), '/', YEAR(date)) AS month_session
  20. FROM
  21.     session
  22.         LEFT JOIN
  23.     club_session ON club_session.id = session.id_club_session
  24.         LEFT JOIN
  25.     club ON club.id = club_session.id_club
  26.         LEFT JOIN
  27.     patient ON patient.id = session.id_patient
  28.         LEFT JOIN
  29.     lookup_club_type ON lookup_club_type.id = club_type
  30.         LEFT JOIN
  31.     lookup_hospital ON lookup_hospital.id = id_hospital
  32.         LEFT JOIN
  33.     tracking_infant ON tracking_infant.id_patient = session.id_patient
  34.         LEFT JOIN
  35.     (SELECT
  36.         id_patient, dob, first_name, last_name
  37.     FROM
  38.         tracking_motherbasicinfo
  39.     LEFT JOIN patient ON patient.id = id_patient
  40.     WHERE
  41.         patient.id IS NOT NULL) tm ON tm.id_patient = session.id_patient
  42.         LEFT JOIN
  43.     lookup_gender ON lookup_gender.id = gender
  44. WHERE
  45.     date BETWEEN @start_date AND @end_date
  46.         AND is_present = 1
  47.         AND linked_to_id_patient = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement