Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. with _all as (\r +
  2. select * from mc_case where create_date >='01.01.2017'\r +
  3. )\r +
  4. , name_mo as (select short_name , po.id\r +
  5. from pim_organization po\r +
  6. join _all on _all.clinic_id=po.id)\r +
  7. , res_count as (select count(template_res_group_id) res_count , _all.clinic_id\r +
  8. from _all\r +
  9. join mc_step ms on ms.case_id=_all.id\r +
  10. join sr_res_group srg on srg.id=ms.res_group_id\r +
  11. GROUP BY _all.clinic_id\r +
  12. )\r +
  13. ,protcol_count as (\r +
  14. select count(msp.id) protcol_count , _all.clinic_id\r +
  15. from _all\r +
  16. join md_srv_rendered msr on msr.case_id=_all.id\r +
  17. join md_srv_protocol msp on msr.id=msp.srv_rendered_id\r +
  18. GROUP BY _all.clinic_id\r +
  19. )\r +
  20. \r +
  21. select distinct name_mo.short_name, res_count.res_count, protcol_count.protcol_count from _all\r+
  22. join name_mo on _all.clinic_id=name_mo.id\r +
  23. join res_count on _all.clinic_id=res_count.clinic_id\r +
  24. join protcol_count on _all.clinic_id=protcol_count.clinic_id\r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement