Book Contents

Book Index

Next Topic

Home

credithistory_query_05.sql

Query

-- Overdue mortgage statistics by year with account type

SELECT Account_Type,

AVG(Days_Overdue) AS Avg_Days,

AVG(Outstanding_Amount) AS Avg_Amount,

COUNT(*) AS Record_Count

FROM CreditHistory_Fact A,

AccountType_Dimension B,

Date_Dimension C

WHERE A.AccountType_Key = B.AccountType_Key

AND A.Date_Key = C.Date_Key

GROUP BY Calendar_Year,Account_Type

ORDER BY Calendar_Year,

Account_Type;

Example

Account_Type | Avg_Days | Avg_Amount | Record_Count

--------------+------------------+------------------+--------------

Checking | 500.261721483555 | 7741.41345971209 | 40012

Current | 501.090460467923 | 7785.66681471225 | 28167

Saving | 496.856415574621 | 7731.76984318532 | 31821