В своем коде SQL я создал таблицу PIVOT для изменения столбцов.Я пытаюсь добавить 2 CALCULATED столбца с именами PendingEffectiveness и ClosingRatio на основе созданных мной столбцов сводной таблицы, но они не рассчитываются должным образом, потому что все, что я получаю, это нули.Вот мой код SQL:
-- Code for Summary Page
SELECT AdjusterName
,COALESCE(BeginningPending,0) as BeginningPending
,COALESCE(TransferredIn,0) as TransferredIn
,COALESCE(TransferredOut,0) as TransferredOut
,COALESCE(FeaturesPending,0) as FeaturesPending
,COALESCE(NewFeatures,0) as NewFeatures
,COALESCE(ClosedFeatures,0) as ClosedFeatures
,COALESCE(BeginningPending / FeaturesPending,0) * 100 as PendingEffectiveness
,COALESCE(ClosedFeatures / NewFeatures,0) / 100 as ClosingRatio
FROM
(
SELECT AdjusterName, [Type], COALESCE(FeatureCount,0) as FeatureCount
FROM [dbo].[RPT_FeaturesByLitigationAdjuster]
GROUP BY AdjusterName, Type, FeatureCount
) as SourceTable
PIVOT (SUM([FeatureCount]) FOR [Type] in ([BeginningPending], [TransferredIn], [TransferredOut], [FeaturesPending], [NewFeatures], [ClosedFeatures])) as PivotTable;
Вот мой набор результатов запроса:
AdjusterName BeginningPending TransferredIn TransferredOut
FeaturesPending NewFeatures ClosedFeatures PendingEffectiveness ClosingRatio
dstallings 51 2 0 53 0 57 0 0
jstrother 28 164 3 36 0 56 0 0
lfaulkner 247 23 8 259 22 94 0 0
rpatton 197 32 12 231 30 59 0 0