Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. select * from dblink('host=kpg01a port=5454 dbname=hcsapdb user=hcs_ap_rw password=hcs_ap_rw',
  2. $$
  3. select app.guid from apsm.ap_appeals app
  4. join
  5. (
  6. select row_number() over (partition by appeal_guid order by create_date desc) "row_number",
  7. planned_execution_date::date,
  8. appeal_guid,
  9. receiver_organization_guid,
  10. create_date::date recieveDate
  11. from apsm.ap_appeal_receivers
  12. ) receivers on receivers.appeal_guid = app.guid
  13. and row_number = 1
  14. and receivers.receiver_organization_guid = 'b0590464-2ec1-4c6d-8894-a4adb57cf684'
  15. and from_hcs
  16. left join
  17. (
  18. select appeal_guid, min(last_editing_date::date) resultDate from apsm.ap_appeal_status_changes
  19. where status in ('EXECUTED', 'ANSWER_IS_NOT_REQUIRED')
  20. group by appeal_guid
  21. ) status_changes on status_changes.appeal_guid = app.guid
  22. where coalesce(resultDate, current_date) - recieveDate > 30
  23. and planned_execution_date < coalesce(resultDate, current_date) and app.status::text not in('NOT_SEND'::text, 'RECALLED'::text)
  24.  
  25. $$
  26. )as s (guid varchar)
  27. full join
  28. (
  29. select * From cap.ap_appeal_processing_datamart
  30. where last_receiver_ppa_organization_guid = 'b0590464-2ec1-4c6d-8894-a4adb57cf684' and deadline_status = 'DEADLINE_FAILED'
  31. ) d on d.guid = s.guid;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement