Advertisement
temaon_lieto

TEst sql

Feb 16th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. SELECT abc.id,
  2. abc.full_name,
  3. COUNT(DISTINCT abc.declaration_patient_id) AS total_counter,
  4. COUNT(DISTINCT abc.patient_id) filter (WHERE abc.is_smoking = TRUE AND
  5. abc.age BETWEEN 18 AND 69) AS smoking_counter,
  6. COUNT(DISTINCT abc.imt_patient_id)
  7. filter (WHERE abc.age BETWEEN 18 AND 69 AND abc.imt_index > 25 AND
  8. abc.imt_asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-15 23:59:59.999999' ) AS overweight_counter,
  9. COUNT(DISTINCT abc.condition_patient_id)
  10. filter (WHERE abc.code IN ('K85', 'K86', 'K87') AND
  11. abc.condition_asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-15 23:59:59.999999' ) AS hypertension_counter,
  12. COUNT(DISTINCT abc.condition_patient_id)
  13. filter (WHERE abc.code IN ('T90') AND
  14. abc.condition_asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-15 23:59:59.999999') AS diabetes_counter,
  15. COUNT(DISTINCT abc.condition_patient_id)
  16. filter (WHERE abc.code IN ('R96') AND
  17. abc.condition_asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-15 23:59:59.999999') AS asthma_counter,
  18. COUNT(DISTINCT abc.condition_patient_id)
  19. filter (WHERE abc.code LIKE 'P%' AND
  20. abc.condition_asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-15 23:59:59.999999') AS derangement_counter,
  21. COUNT(DISTINCT abc.reception_patient_id)
  22. filter (WHERE abc.reception_asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-15 23:59:59.999999') AS reception_counter
  23. FROM mv_stat_lvl_2_test_view abc
  24. WHERE "abc"."legal_entity_id" = 3228
  25. AND "abc"."employee_type_ref_value" = 'DOCTOR'
  26. GROUP BY abc.id, abc.full_name
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement