这是我的查询,它返回从年初至今的政策计数。我想知道如何处理仅影响等于“活动”状态的语句。
select distinct
count(pol3.CT_ID + pol3.CT_NSID) as 'YTD',
pol3.ct_status
from contract pol3
where (pol3.CT_Status = 'Quote' or pol3.ct_status='Active' or pol3.ct_status='Declined')
and Year(pol3.CT_Subscription_Date)>= datediff(year,(DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)), getdate())
group by pol3.ct_status
这是当前的输出:
我试着做
select distinct
count(pol3.CT_ID + pol3.CT_NSID) as 'YTD',
pol3.ct_status
from contract pol3
where (pol3.CT_Status = 'Quote' or pol3.ct_status='Active' or pol3.ct_status='Declined')
and CT_ORIGINAL_QUOTE_ID is not null
and CT_ORIGINAL_QUOTE_NSID is not null
and Year(pol3.CT_Subscription_Date)>= datediff(year,(DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)), getdate())
group by pol3.ct_status
这显然是错误的,因为它针对所有三种状态。如何使 ct_original_* 仅针对活动状态?任何线索或指针将不胜感激。