如何在一个查询中返回每个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
目前的结果如下:
但理想的结果如下:
答案 0 :(得分:0)
这个怎么样?
onItemLongClicked