jeniferfleurant

pcr_postive_pcr2_positive_and_pcr1neg__on_arv

Dec 4th, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. select count(*) as pcr_postive_pcr2_positive_and_pcr1neg__on_arv from (
  2.  
  3. select b.* from (
  4.  
  5. SELECT id_patient,pcr_result FROM testing_specimen where pcr_result=1 and which_pcr=2 and id_patient in (
  6.  
  7. SELECT ab1.id_patient from (
  8.  
  9. SELECT id_patient,pcr_result FROM testing_specimen where pcr_result<>1 and which_pcr=1
  10.  
  11. union select id_patient,result as pcr_result from testing_result where result<>1 and which_pcr=1
  12.  
  13. ) ab1
  14.  
  15. )
  16.  
  17. union select id_patient,result as pcr_result from testing_result where result=1 and which_pcr=2 and id_patient in (
  18.  
  19. SELECT ab2.id_patient from (
  20.  
  21. SELECT id_patient,pcr_result FROM testing_specimen where pcr_result<>1 and which_pcr=1
  22.  
  23. union select id_patient,result as pcr_result from testing_result where result<>1 and which_pcr=1) ab2)
  24.  
  25.  
  26.  
  27.  
  28. ) b
  29.  
  30. left join tracking_regime r on r.id_patient=b.id_patient
  31.  
  32. where r.id is not null group by b.id_patient
  33.  
  34.  
  35.  
  36.  
  37. ) a
Advertisement
Add Comment
Please, Sign In to add comment