

            select
             count(  * ) AS cnt 
            from
             -- from
                v_EvnPL ESP
                left join lateral(
                    select
                    	EvnStickBase_id,
                    	EvnStickBase_IsFSS
                    from v_EvnStickBase
                    where
                        EvnStickBase_id in (
                            select EvnStickBase_id from v_EvnStickBase where EvnStickBase_mid = ESP.EvnPL_id
                            union all
                            select EvnStickBase_id from v_EvnStickBase where EvnStickBase_rid =  ESP.EvnPL_id
                            union all
                            select Evn_lid from v_EvnLink where Evn_id =  ESP.EvnPL_id
                    )
                    limit 1
                ) as ESB on true
                inner join v_PersonState PS on PS.Person_id = ESP.Person_id
                --left join StickType ST on ST.StickType_id = ES.StickType_id
                
                
                left join v_MedPersonal MP on MP.MedPersonal_id = ESP.MedPersonal_id and MP.Lpu_id = ESP.Lpu_id
                left join v_LpuSection LS on LS.LpuSection_id = ESP.LpuSection_id
                left join v_Job Job on Job.Job_id = PS.Job_id
                left join Org PJ on PJ.Org_id = Job.Org_id
                left join Post PP on PP.Post_id = Job.Post_id
            -- end from
            WHERE
                -- where
                ESP.Lpu_id = '13101853'
                 and LS.LpuBuilding_id = '890101000000107'
                -- end where
            
        
