Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. SELECT
  2. p1.patient_code AS primary_patient_code,
  3. a.*,
  4. lh.name AS current_hospital_name,
  5. CONCAT(lh.city_code, '/', lh.hospital_code) AS current_site_code
  6. FROM
  7. (SELECT
  8. linked_to_id_patient AS id_patient,
  9. GROUP_CONCAT(patient_code
  10. SEPARATOR '&&') AS linked_code,
  11. COUNT(linked_to_id_patient) AS numb
  12. FROM
  13. patient p
  14. WHERE
  15. linked_to_id_patient != 0
  16. GROUP BY linked_to_id_patient) a
  17. left join patient p1 on p1.id=a.id_patient
  18. left join tracking_motherbasicinfo tmi on tmi.id_patient = p.a.id_patient
  19. left join tracking_infant ti on ti.id_patient=a.id_patient
  20. left join lookup_hospital lh on lh.id=ti.id_hospital
  21.  
  22. where tmi.id is null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement