
            select
                 count(  * ) AS cnt 
            from
                -- from
                stg.v_ServiceListPackage SLP
                left join stg.v_ServiceListPackageType SLPT on SLPT.ServiceListPackageType_id = SLP.ServiceListPackageType_id
                left join stg.v_ServiceListProcDataType SLPDT on SLPDT.ServiceListProcDataType_id = SLP.ServiceListProcDataType_id
                left join stg.v_PackageRouteType PRT on PRT.PackageRouteType_id = SLPT.PackageRouteType_id
                left join stg.v_PackageStatus PS on PS.PackageStatus_id = SLP.PackageStatus_id
                
                left join lateral (
                    select SLDL.*
                    from stg.v_ServiceListDetailLog SLDL
                    where SLDL.ServiceListPackage_id = SLP.ServiceListPackage_id
                    order by SLDL.ServiceListDetailLog_id desc
                    limit 1
                ) SLDL on true
            
                left join lateral (
                    select SP.ServicePackage_Data
                    from stg.v_ServicePackage SP
                    where SP.ServiceListPackage_id = SLP.ServiceListPackage_id
                    and (SP.ServicePackage_IsResp is null or SP.ServicePackage_IsResp = 1)
                    ORDER BY SP.ServicePackage_insDT DESC
                    limit 1
                ) SP_Request on true
                left join lateral (
                    select SP.ServicePackage_Data
                    from stg.v_ServicePackage SP
                    where SP.ServiceListPackage_id = SLP.ServiceListPackage_id
                    and SP.ServicePackage_IsResp = 2
                    ORDER BY SP.ServicePackage_insDT DESC
                    limit 1
                ) SP_Response on true
                -- end from
            where
             	-- where
                SLP.ServiceListLog_id = '520101000000990'
and SLP.Lpu_id = '2867'
                -- end where
            
        
