如何获得每个Mod的每个InsuredCounty和Average的总数

时间:2017-08-14 17:05:36

标签: sql-server tsql sql-server-2012 totals

如何在一个查询中返回每个InsuredCounty的总保费和ExperienceMod,SchedureMod,TerritoryMod,EffectiveMod的平均值?

select * 
from (SELECT Insured,
             InsuredCounty,
             PolicyNumber,
             EffectiveDate,
             PolicyType,
             SUM(Premium) as Premium,
             ExperienceMod,
             ISNULL(ScheduleMod,0) as ScheduleMod,
             TerritoryMod,
             ISNULL(EffectiveMod,0) as EffectiveMod,
            ROW_NUMBER() OVER (PARTITION BY Insured,PolicyNumber,Premium, TransactionType ORDER BY PolicyType DESC) as rid 
      FROM ProductionReportMetrics
      WHERE EffectiveDate <= EOMONTH(GETDATE())
      AND CompanyLine = 'Arch Insurance Company' 
      AND Insured <>'Jerry''s Test' 
      AND TransactionType = 'Policy'
      GROUP BY  Insured,
                InsuredCounty,
                PolicyNumber,
                PolicyType,
                EffectiveDate,
                experienceMod,
                ScheduleMod,
                TerritoryMod,
                EffectiveMod, 
                Premium,
                EffectiveDate,
                TransactionType
      ) b 
where rid = 1 
ORDER BY  InsuredCounty, Premium desc, EffectiveDate

目前的结果如下:

enter image description here

但理想的结果如下:

enter image description here

1 个答案:

答案 0 :(得分:0)

这个怎么样?

onItemLongClicked