jeniferfleurant

Followup Q1 Q2

Apr 9th, 2019
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.79 KB | None | 0 0
  1. USE caris_db;
  2. SET
  3.   @start_date = "2019-01-01";
  4. SET
  5.   @end_date = "2019-03-31";
  6. SET
  7.   @start_date_last = "2018-10-01";
  8. SET
  9.     @end_date_last = "2018-12-31";
  10. select patient_code, if(q1 is not null,'yes','no') as q1, if(q2 is not null,'yes','no') as q2  from((
  11. (select id_patient from  tracking_followup where date between @start_date_last and @end_date_last)
  12. union
  13. (select id_patient from  tracking_followup where date between @start_date and @end_date)
  14. )unio
  15. left join
  16. (select distinct id_patient as q2 from  tracking_followup where date between @start_date and @end_date)x
  17. on unio.id_patient=q2
  18. left join
  19. (select distinct id_patient as q1 from  tracking_followup where date between @start_date_last and @end_date_last)y
  20. on unio.id_patient=q1
  21. left join patient on patient.id=unio.id_patient
  22. )
Advertisement
Add Comment
Please, Sign In to add comment