jeniferfleurant

EID (Miss Erlyne)

Apr 13th, 2018
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.23 KB | None | 0 0
  1. USE caris_db;
  2. SET @start_date='2016-10-01';
  3. SET @end_date='2017-09-30';
  4. select left(patient_code,8) as hospital, sum(which_pcr=5) as pcr_n, sum(which_pcr=1)as pcr_1, sum(which_pcr=2) as pcr2, count(detecte) as detecte, count(on_arv) as on_arv, count(confirmation) as confirmation
  5. from testing_specimen
  6. left join
  7. patient on patient.id=id_patient
  8. left join
  9. (select distinct id_patient as detecte from testing_specimen where pcr_result=1)a on detecte=id_patient
  10. left join
  11. (select * from(
  12. select distinct id_patient as on_arv from tracking_followup where on_arv=1
  13. union
  14. select distinct id_patient as on_arv from tracking_regime where category='regime_infant_treatment'
  15. )a where on_arv in (select id_patient from tracking_infant where is_dead=0 or death_date>=death_date)
  16. and on_arv in(select distinct id_patient as detecte from testing_specimen where pcr_result=1)
  17. )s on on_arv=id_patient
  18. left join(
  19. select id_patient as confirmation from testing_specimen t1 where pcr_result=1 and id_patient in
  20. (select id_patient from testing_specimen t2 where pcr_result=1 and t1.date_blood_taken<t2.date_blood_taken)
  21. )za on confirmation=id_patient
  22. where date_blood_taken between @start_date and @end_date and linked_to_id_patient=0
  23. group by hospital
Advertisement
Add Comment
Please, Sign In to add comment