-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask7.sql
More file actions
39 lines (31 loc) · 746 Bytes
/
task7.sql
File metadata and controls
39 lines (31 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use financial16_25;
DROP TABLE IF EXISTS tmp_analysis;
CREATE TEMPORARY TABLE tmp_analysis AS
SELECT
c.gender,
2023 - extract(year from birth_date) as age,
-- agregaty
sum(l.amount) as loans_amount,
count(l.amount) as loans_count -- na późniejsze potrzeby
FROM
loan as l
INNER JOIN
account a using (account_id)
INNER JOIN
disp as d using (account_id)
INNER JOIN
client as c using (client_id)
WHERE True
AND l.status IN ('A', 'C')
AND d.type = 'OWNER'
GROUP BY c.gender, 2
;
select * from tmp_analysis;
SELECT SUM(loans_count) FROM tmp_analysis
;
SELECT
gender,
avg(age) as avg_age
FROM tmp_analysis
GROUP BY gender
;