Query
-- Overdue mortgage statistics by year with mortgage type
SELECT Mortgage_Type,
AVG(Days_Overdue) AS Avg_Days,
AVG(Outstanding_Amount) AS Avg_Amount,
COUNT(*) AS Overdue_Recs
FROM CreditHistory_Fact A,
Mortgage_Dimension B,
Date_Dimension C
WHERE A.Mortgage_Key = B.Mortgage_Key
AND A.Date_Key = C.Date_Key
GROUP BY Calendar_Year,Mortgage_Type
ORDER BY Calendar_Year,
Mortgage_Type;
Example
Mortgage_Type | Avg_Days | Avg_Amount | Overdue_Recs
---------------+------------------+------------------+--------------
Car | 499.179450730653 | 7758.45090843616 | 105522
Home | 499.670780499164 | 7742.27507610237 | 94478
(2 rows)