
            SELECT
                emdjq."EMDJournalQuery_id",
                emdjq."EMDRegistry_id",
                emdv."EMDVersion_FilePath",
                emddtl."EMDDocumentTypeLocal_Name",
                emdqt."EMDQueryType_Name",
                emdr."EMDRegistry_Num",
                to_char(emdjq."EMDJournalQuery_OutDT", 'DD.MM.YYYY HH24:MI:SS') as "EMDJournalQuery_OutDT_RU",
                emdqs."EMDQueryStatus_Name",
                to_char(emdjq."EMDJournalQuery_InDT", 'DD.MM.YYYY HH24:MI:SS') as "EMDJournalQuery_InDT",
                emdr."Lpu_id",
                emdjq."EMDJournalQuery_OutDT",
                count(*) OVER() AS "totalCount" 		/*современная возможность получения кол-ва записей без учета LIMIT*/

            FROM
                "EMD"."EMDJournalQuery" emdjq
                inner join "EMD"."EMDRegistry" emdr on emdr."EMDRegistry_id" = emdjq."EMDRegistry_id"
                inner join "EMD"."EMDDocumentTypeLocal" emddtl on emddtl."EMDDocumentTypeLocal_id" = emdr."EMDDocumentTypeLocal_id"
                inner join "EMD"."EMDDocumentType" emddt on emddt."EMDDocumentType_id" = emddtl."EMDDocumentType_id"
                left join "EMD"."EMDQueryType" emdqt on emdqt."EMDQueryType_id" = emdjq."EMDQueryType_id"
                left join "EMD"."EMDQueryStatus" emdqs on emdqs."EMDQueryStatus_id" = emdjq."EMDQueryStatus_id"
                left join lateral (
                    select
                        "EMDVersion_FilePath"
                    from
                        "EMD"."EMDVersion"
                    where
                        "EMDRegistry_id" = emdjq."EMDRegistry_id" order by "EMDRegistry_id" desc
                    fetch first 1 row only
                ) emdv on true
            WHERE
                (1=1)  and emddt."EMDDocumentType_Code" = -28 and emdjq."EMDQueryStatus_id" = '0'
            ORDER BY emdjq."EMDJournalQuery_OutDT" DESC
            LIMIT 100
            OFFSET 0
