sql server - How to get a total for each InsuredCounty and Average for each Mod -
how can return total premium each insuredcounty , average experiencemod, scheduremod,territorymod, effectivemod in 1 query?
select * (select insured, insuredcounty, policynumber, effectivedate, policytype, sum(premium) premium, experiencemod, isnull(schedulemod,0) schedulemod, territorymod, isnull(effectivemod,0) effectivemod, row_number() on (partition insured,policynumber,premium, transactiontype order policytype desc) rid productionreportmetrics effectivedate <= eomonth(getdate()) , companyline = 'arch insurance company' , insured <>'jerry''s test' , transactiontype = 'policy' group insured, insuredcounty, policynumber, policytype, effectivedate, experiencemod, schedulemod, territorymod, effectivemod, premium, effectivedate, transactiontype ) b rid = 1 order insuredcounty, premium desc, effectivedate
currently outcome looks this:
but desirable outcome that:
what this?
with cte ( select insuredcounty insuredcountry , premium premium , experiencemod experiencemod , scheduremod scheduremod , territorymod territorymod , effectivemod effectivemod productionreportmetrics effectivedate <= eomonth(getdate()) , companyline = 'arch insurance company' , insured <>'jerry''s test' , transactiontype = 'policy' ) select insuredcountry , sum(premium) premium , avg(experiencemod) experiencemod , avg(scheduremod) scheduremod , avg(territorymod) territorymod , avg(effectivemod) effectivemod cte group insuredcountry order insuredcounty, premium desc, effectivedate;
Comments
Post a Comment