
                with tmp as (
                    select
                        ms.MedService_id,
                        ut.UslugaTest_id
                    from v_UslugaTest ut
                        inner join v_EvnLabSample els on els.EvnLabSample_id = ut.EvnLabSample_id
                        inner join v_MedService ms on ms.MedService_id = els.MedService_id
                        inner join v_Lpu l on ms.Lpu_id = l.Lpu_id
                        inner join v_EvnLabRequest elr on els.EvnLabRequest_id = elr.EvnLabRequest_id
                    where 1=1
                        and elr.EvnLabRequest_insDt >= '2022-05-02'
                        and elr.EvnLabRequest_insDt <= '2022-05-08'
                        and ms.MedService_endDT is null
                        and ms.MedServiceType_id = 6
                )
                select
                    MedService_id as "MedService_id",
                    count(UslugaTest_id) count
                from tmp
                group by MedService_id
            
