File tree 1 file changed +57
-0
lines changed
1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ use financial16_25;
2
+
3
+ WITH cte AS (
4
+ SELECT
5
+ d2 .district_id ,
6
+
7
+ count (distinct c .client_id ) as customer_amount,
8
+ sum (l .amount ) as loans_given_amount,
9
+ count (l .amount ) as loans_given_count
10
+ FROM
11
+ loan as l
12
+ INNER JOIN
13
+ account a using (account_id)
14
+ INNER JOIN
15
+ disp as d using (account_id)
16
+ INNER JOIN
17
+ client as c using (client_id)
18
+ INNER JOIN
19
+ district as d2 on
20
+ c .district_id = d2 .district_id
21
+ WHERE True
22
+ AND l .status IN (' A' , ' C' )
23
+ AND d .type = ' OWNER'
24
+ GROUP BY d2 .district_id
25
+ ;
26
+ )
27
+ SELECT *
28
+ FROM cte
29
+
30
+
31
+ WITH cte AS (
32
+ SELECT d2 .district_id ,
33
+
34
+ count (distinct c .client_id ) as customer_amount,
35
+ sum (l .amount ) as loans_given_amount,
36
+ count (l .amount ) as loans_given_count
37
+ FROM
38
+ loan as l
39
+ INNER JOIN
40
+ account a using (account_id)
41
+ INNER JOIN
42
+ disp as d using (account_id)
43
+ INNER JOIN
44
+ client as c using (client_id)
45
+ INNER JOIN
46
+ district as d2 on
47
+ c .district_id = d2 .district_id
48
+ WHERE True
49
+ AND l .status IN (' A' , ' C' )
50
+ AND d .type = ' OWNER'
51
+ GROUP BY d2 .district_id
52
+ )
53
+ SELECT
54
+ * ,
55
+ loans_given_amount / SUM (loans_given_amount) OVER () AS share
56
+ FROM cte
57
+ ORDER BY share DESC
You can’t perform that action at this time.
0 commit comments