I have the following table data:
SELECT [Quote ID], [Deductible Plan], [Age ID], [Number of Members]
FROM finalResult_001
1381 $750 Deductible Plan Age 65 10
1381 $750 Deductible Plan Age 85+ 10
1371 $150 Deductible Plan Age 65 10
1371 $150 Deductible Plan Age 85+ 10
I am looking for the following result:
Quote ID Deductible Plan Age 65 Age 85+
1381 $750 Deductible Plan 10 10
1371 $150 Deductible Plan 10 10
I want to Group by Quote ID and Deductible Plan and should sum by Age ID column, however I am not sure how to do it, here is my try:
SELECT [Quote ID], [Deductible Plan],
case when [Age ID] = 'Age 65' THEN SUM([Number of Members]) else 0 END AS [Age 65],
case when [Age ID] = 'Age 85+' THEN SUM([Number of Members]) else 0 END AS [Age 85+]
FROM finalResult_001
GROUP BY [Quote ID], [Age ID], [Deductible Plan]
THe result:
Quote ID Deductible Plan Age 65 Age 85+
1381 $750 Deductible Plan 0 10
1381 $750 Deductible Plan 10 0
1371 $150 Deductible Plan 0 10
1371 $150 Deductible Plan 10 0
how would I sum the Age ID to give me the resule:
Quote ID Deductible Plan Age 65 Age 85+
1381 $750 Deductible Plan 10 10
1371 $150 Deductible Plan 10 10