select R.Registry_id as "Registry_id", R.RegistryType_id as "RegistryType_id", RS.RegistryStatus_id as "RegistryStatus_id", RS.RegistryStatus_SysNick as "RegistryStatus_SysNick", R.Registry_IsActive as "Registry_IsActive", coalesce(R.Registry_IsNeedReform, 1) as "Registry_IsNeedReform", RTrim(R.Registry_Num) as "Registry_Num", to_char(R.Registry_insDT, 'dd.mm.yyyy') as "Registry_insDT", to_char(R.Registry_accDate, 'dd.mm.yyyy') as "Registry_accDate", to_char(R.Registry_begDate, 'dd.mm.yyyy') as "Registry_begDate", to_char(R.Registry_endDate, 'dd.mm.yyyy') as "Registry_endDate", R.Lpu_id as "Lpu_id", R.Registry_xmlExportPath as "Registry_xmlExportPath", DC.DispClass_id as "DispClass_id", DC.DispClass_Name as "DispClass_Name", R.PayType_id as "PayType_id", PT.PayType_Name as "PayType_Name", PT.PayType_SysNick as "PayType_SysNick", R.KatNasel_id as "KatNasel_id", KN.KatNasel_Name as "KatNasel_Name", KN.KatNasel_SysNick as "KatNasel_SysNick", R.OrgRSchet_id as "OrgRSchet_id", R.OrgSMO_id as "OrgSMO_id", R.Org_mid as "Org_mid", R.Registry_IsRepeated as "Registry_IsRepeated", R.Registry_IsLocked as "Registry_IsLocked", case when R.Registry_IsRepeated = 2 then 'Исправительный' else 'Основной' end as "RegistryUnionText", case when KN.KatNasel_Code = 1 then OS.OrgSMO_Name else 'ТФОМС КБР' end as "PayText", case when R.Registry_IsZNO = 2 then 'true' else 'false' end as "Registry_IsZNO", LB.LpuBuilding_Name as "LpuBuilding_Name", coalesce(R.Registry_RecordCount, 0) as "Registry_Count", coalesce(R.Registry_ErrorCount, 0) as "Registry_ErrorCount", RegistryErrorCom.RegistryErrorCom_IsData as "RegistryErrorCom_IsData", RegistryError.RegistryError_IsData as "RegistryError_IsData", RegistryNoPolis.RegistryNoPolis_IsData as "RegistryNoPolis_IsData", RegistryErrorTFOMS.RegistryErrorTFOMS_IsData as "RegistryErrorTFOMS_IsData", RegistryNoPay.RegistryNoPay_IsData as "RegistryNoPay_IsData", coalesce(R.Registry_Sum, 0.00) as "Registry_Sum", 0.00 as "Registry_SumNoErr", 0.00 as "Registry_SumPaid", case when RQ.RegistryQueue_id is not null then 1 else 0 end as "Registry_IsProgress", '' as "Registry_lastExpDate", to_char(R.Registry_updDT, 'dd.mm.yyyy hh24:mi:ss') as "Registry_updDate", to_char(RQH.RegistryQueueHistory_endDT, 'dd.mm.yyyy hh24:mi:ss') as "ReformTime", RGT.RegistryGroupType_Name as "RegistryGroupType_Name", RGT.RegistryGroupType_Code as "RegistryGroupType_Code", RCS.RegistryCheckStatus_id as "RegistryCheckStatus_id", RCS.RegistryCheckStatus_Code as "RegistryCheckStatus_Code", RCS.RegistryCheckStatus_Name as "RegistryCheckStatus_Name", case when RS.RegistryStatus_SysNick = 'paid' then '2' else '1' end as "Registry_IsPaid", OS.OrgSMO_Nick as "OrgSMO_Nick", '' as "Error_Message" from r68.v_Registry R left join v_RegistryGroupType RGT on RGT.RegistryGroupType_id = R.RegistryGroupType_id left join v_RegistryCheckStatus RCS on RCS.RegistryCheckStatus_id = R.RegistryCheckStatus_id left join v_DispClass DC on DC.DispClass_id = R.DispClass_id left join v_PayType PT on PT.PayType_id = R.PayType_id left join v_KatNasel KN on KN.KatNasel_id = R.KatNasel_id left join v_LpuBuilding LB on LB.LpuBuilding_id = R.LpuBuilding_id left join v_OrgSMO OS on OS.OrgSMO_id = R.OrgSMO_id left join RegistryStatus RS on RS.RegistryStatus_id = R.RegistryStatus_id left join lateral( select RegistryQueue_id from r68.v_RegistryQueue where Registry_id = R.Registry_id limit 1 ) RQ on true left join lateral( select RegistryQueueHistory_endDT from r68.RegistryQueueHistory where Registry_id = R.Registry_id and RegistryQueueHistory_endDT is not null order by RegistryQueueHistory_id desc limit 1 ) RQH on true left join lateral( select case when RE.Registry_id is not null then 1 else 0 end as RegistryErrorCom_IsData from r68.v_RegistryErrorCom RE where RE.Registry_id = R.Registry_id limit 1 ) RegistryErrorCom on true left join lateral( select case when RE.Registry_id is not null then 1 else 0 end as RegistryError_IsData from r68.v_RegistryError RE where RE.Registry_id = R.Registry_id limit 1 ) RegistryError on true left join lateral( select case when RE.Registry_id is not null then 1 else 0 end as RegistryNoPolis_IsData from r68.v_RegistryNoPolis RE where RE.Registry_id = R.Registry_id limit 1 ) RegistryNoPolis on true left join lateral( select case when RE.Registry_id is not null then 1 else 0 end as RegistryErrorTFOMS_IsData from r68.v_RegistryErrorTFOMS RE where RE.Registry_id = R.Registry_id limit 1 ) RegistryErrorTFOMS on true left join lateral( select case when RD.Registry_id is not null then 1 else 0 end as RegistryNoPay_IsData from r68.v_RegistryData RD where RD.Registry_id = R.Registry_id and RD.Paid_id = 1 limit 1 ) RegistryNoPay on true where (1=1) and R.Lpu_id = '680101000000001' and R.RegistryType_id = '16' and RS.RegistryStatus_SysNick = 'work' order by R.Registry_endDate DESC, RQH.RegistryQueueHistory_endDT DESC execution time: 0.1770761013 fetching time: 0.0000438690 [{"Registry_id":"680101000000581","RegistryType_id":"16","RegistryStatus_id":"3","RegistryStatus_SysNick":"work","Registry_IsActive":"2","Registry_IsNeedReform":"1","Registry_Num":"\u0442\u0435\u0441\u04422","Registry_insDT":"11.12.2020","Registry_accDate":"11.12.2020","Registry_begDate":"01.11.2020","Registry_endDate":"30.11.2020","Lpu_id":"680101000000001","Registry_xmlExportPath":null,"DispClass_id":null,"DispClass_Name":null,"PayType_id":"680101000000008","PayType_Name":"\u041e\u041c\u0421","PayType_SysNick":"oms","KatNasel_id":"680101000000003","KatNasel_Name":"\u0412\u0441\u0435 \u043d\u0430\u0441\u0435\u043b\u0435\u043d\u0438\u0435","KatNasel_SysNick":"all","OrgRSchet_id":null,"OrgSMO_id":null,"Org_mid":null,"Registry_IsRepeated":"1","Registry_IsLocked":null,"RegistryUnionText":"\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439","PayText":"\u0422\u0424\u041e\u041c\u0421 \u041a\u0411\u0420","Registry_IsZNO":"true","LpuBuilding_Name":null,"Registry_Count":"0","Registry_ErrorCount":"0","RegistryErrorCom_IsData":null,"RegistryError_IsData":null,"RegistryNoPolis_IsData":null,"RegistryErrorTFOMS_IsData":null,"RegistryNoPay_IsData":null,"Registry_Sum":"0.00","Registry_SumNoErr":"0.00","Registry_SumPaid":"0.00","Registry_IsProgress":"0","Registry_lastExpDate":"","Registry_updDate":"11.12.2020 13:44:01","ReformTime":"11.12.2020 13:44:02","RegistryGroupType_Name":null,"RegistryGroupType_Code":null,"RegistryCheckStatus_id":null,"RegistryCheckStatus_Code":null,"RegistryCheckStatus_Name":null,"Registry_IsPaid":"1","OrgSMO_Nick":null,"Error_Message":""},{"Registry_id":"680101000000532","RegistryType_id":"16","RegistryStatus_id":"3","RegistryStatus_SysNick":"work","Registry_IsActive":"2","Registry_IsNeedReform":"1","Registry_Num":"\u0442\u0435\u0441\u0442","Registry_insDT":"10.12.2020","Registry_accDate":"10.12.2020","Registry_begDate":"01.10.2020","Registry_endDate":"31.10.2020","Lpu_id":"680101000000001","Registry_xmlExportPath":null,"DispClass_id":null,"DispClass_Name":null,"PayType_id":"680101000000008","PayType_Name":"\u041e\u041c\u0421","PayType_SysNick":"oms","KatNasel_id":"680101000000003","KatNasel_Name":"\u0412\u0441\u0435 \u043d\u0430\u0441\u0435\u043b\u0435\u043d\u0438\u0435","KatNasel_SysNick":"all","OrgRSchet_id":null,"OrgSMO_id":null,"Org_mid":null,"Registry_IsRepeated":"1","Registry_IsLocked":null,"RegistryUnionText":"\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439","PayText":"\u0422\u0424\u041e\u041c\u0421 \u041a\u0411\u0420","Registry_IsZNO":"false","LpuBuilding_Name":null,"Registry_Count":"2","Registry_ErrorCount":"0","RegistryErrorCom_IsData":null,"RegistryError_IsData":null,"RegistryNoPolis_IsData":null,"RegistryErrorTFOMS_IsData":null,"RegistryNoPay_IsData":null,"Registry_Sum":"727.04","Registry_SumNoErr":"0.00","Registry_SumPaid":"0.00","Registry_IsProgress":"0","Registry_lastExpDate":"","Registry_updDate":"22.12.2020 15:12:02","ReformTime":"22.12.2020 15:12:40","RegistryGroupType_Name":null,"RegistryGroupType_Code":null,"RegistryCheckStatus_id":null,"RegistryCheckStatus_Code":null,"RegistryCheckStatus_Name":null,"Registry_IsPaid":"1","OrgSMO_Nick":null,"Error_Message":""}]