jeniferfleurant icon

Followup Q1 Q2

jeniferfleurant | PRO | 04/09/19 12:19:36 PM UTC | 0 ⭐ | 265 👁️ | Never ⏰ | []
MySQL |

790 B

|

None

|

0 👍

/

0 👎

USE caris_db;
SET
  @start_date = "2019-01-01";
SET
  @end_date = "2019-03-31";
SET
  @start_date_last = "2018-10-01";
SET
    @end_date_last = "2018-12-31";
select patient_code, if(q1 is not null,'yes','no') as q1, if(q2 is not null,'yes','no') as q2  from((
(select id_patient from  tracking_followup where date between @start_date_last and @end_date_last)
union
(select id_patient from  tracking_followup where date between @start_date and @end_date)
)unio
left join
(select distinct id_patient as q2 from  tracking_followup where date between @start_date and @end_date)x
on unio.id_patient=q2
left join
(select distinct id_patient as q1 from  tracking_followup where date between @start_date_last and @end_date_last)y
on unio.id_patient=q1
left join patient on patient.id=unio.id_patient
)

Comments