Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ce7a430

Browse files
authoredMar 12, 2024
Add files via upload
1 parent dc1ad47 commit ce7a430

File tree

3 files changed

+40344
-0
lines changed

3 files changed

+40344
-0
lines changed
 

‎final_data.csv

Lines changed: 40314 additions & 0 deletions
Large diffs are not rendered by default.

‎final_data.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT *
2+
FROM final_data
3+
LIMIT 10;

‎final_data_task_2.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
WITH CTE AS (
2+
SELECT
3+
customer_id,
4+
contract_id,
5+
contract_serial_number,
6+
issue_dt,
7+
loan_amount,
8+
EXTRACT(YEAR FROM issue_dt) AS year,
9+
EXTRACT(MONTH FROM issue_dt) AS month,
10+
FIRST_VALUE(loan_amount) OVER (PARTITION BY customer_id ORDER BY issue_dt) AS first_loan_amount,
11+
LAST_VALUE(loan_amount) OVER (PARTITION BY customer_id ORDER BY issue_dt RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS last_loan_amount,
12+
RANK() OVER (PARTITION BY EXTRACT(YEAR FROM issue_dt), EXTRACT(MONTH FROM issue_dt) ORDER BY contract_serial_number DESC) AS rank
13+
FROM final_data
14+
WHERE EXTRACT(YEAR FROM issue_dt) = 2019
15+
)
16+
17+
SELECT
18+
year,
19+
month,
20+
customer_id,
21+
MAX(contract_serial_number) AS max_contract_serial_number,
22+
(last_loan_amount / NULLIF(first_loan_amount, 0)) AS loan_growth_factor
23+
FROM CTE
24+
WHERE rank = 1
25+
GROUP BY year, month, customer_id, first_loan_amount, last_loan_amount
26+
ORDER BY year, month, customer_id;
27+

0 commit comments

Comments
 (0)
Please sign in to comment.