0
其中一列Im拾取的是PolicyType
,条件是TransactionType = 'Policy'
。 但有时相同的Insured
可以具有相同的TransactionType
值,但具有不同的PolicyType
值。所以,如果我有相同的投保TransactionType
,但不同PolicyType
- 如何优先和选择具有PolicyType ='Rewrite'
的记录,并忽略与PolicyType='New Business'
? 应该是简单CASE
语句,但我很困惑 如何不根据列名称选取具有优先级的记录
SELECT CAST(YEAR(EffectiveDate) as CHAR(4))+'/'+ CAST(MONTH(EffectiveDate) AS VARCHAR(2)) AS YearMonth,
Insured,
PolicyNumber,
EffectiveDate,
PolicyType,
TransactionType,
SUM(Premium) as Premium,
ExperienceMod,
ISNULL(ScheduleMod,0) as ScheduleMod,
TerritoryMod,
ISNULL(EffectiveMod,0) as EffectiveMod
FROM ProductionReportMetrics
WHERE EffectiveDate >=DateAdd(yy, -1, DATEADD(d, 1, EOMONTH(GETDATE()))) AND EffectiveDate <= EOMONTH(GETDATE())
AND CompanyLine = 'Arch Insurance Company' AND Insured <>'Jerry''s Test' AND TransactionType = 'Policy' --and PolicyNumber ='ZAWCI2517900'
GROUP BY Insured,
PolicyNumber,
PolicyType,
TransactionType,
EffectiveDate,
experienceMod,ScheduleMod,TerritoryMod,EffectiveMod, Premium,EffectiveDate
ORDER BY YEAR(EffectiveDate), (MONTH(EffectiveDate)), PolicyType
真棒!!!!!!!!!!非常感谢Dance @ Henry – Oleg