Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select * from dblink('host=kpg01a port=5454 dbname=hcsapdb user=hcs_ap_rw password=hcs_ap_rw',
- $$
- select app.guid from apsm.ap_appeals app
- join
- (
- select row_number() over (partition by appeal_guid order by create_date desc) "row_number",
- planned_execution_date::date,
- appeal_guid,
- receiver_organization_guid,
- create_date::date recieveDate
- from apsm.ap_appeal_receivers
- ) receivers on receivers.appeal_guid = app.guid
- and row_number = 1
- and receivers.receiver_organization_guid = 'b0590464-2ec1-4c6d-8894-a4adb57cf684'
- and from_hcs
- left join
- (
- select appeal_guid, min(last_editing_date::date) resultDate from apsm.ap_appeal_status_changes
- where status in ('EXECUTED', 'ANSWER_IS_NOT_REQUIRED')
- group by appeal_guid
- ) status_changes on status_changes.appeal_guid = app.guid
- where coalesce(resultDate, current_date) - recieveDate > 30
- and planned_execution_date < coalesce(resultDate, current_date) and app.status::text not in('NOT_SEND'::text, 'RECALLED'::text)
- $$
- )as s (guid varchar)
- full join
- (
- select * From cap.ap_appeal_processing_datamart
- where last_receiver_ppa_organization_guid = 'b0590464-2ec1-4c6d-8894-a4adb57cf684' and deadline_status = 'DEADLINE_FAILED'
- ) d on d.guid = s.guid;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement