Advertisement
suburg

Untitled

Aug 11th, 2022
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. SELECT
  2. v.root_guid AS drso_guid,
  3. MAX(supply_period_end) AS supply_period_end,
  4. COUNT(DISTINCT house_code) AS house_count
  5. FROM
  6. agrsm.agr_rso_documents v
  7. INNER JOIN agrsm.agr_rso_houses rso_houses ON v.root_guid = rso_houses.agreement_guid
  8. INNER JOIN agrsm.agr_rso_house_services house_serv ON house_serv.rso_house_guid = rso_houses.guid
  9. WHERE
  10. house_serv.supply_period_end IS NOT NULL
  11. AND house_serv.supply_period_end BETWEEN '2022-07-25'::date AND '2022-08-04'::date
  12. AND v.version BETWEEN rso_houses.lo_doc_version AND rso_houses.hi_doc_version
  13. GROUP BY
  14. v.root_guid
  15. ORDER BY
  16. COUNT(DISTINCT house_code) DESC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement