File tree 1 file changed +44
-0
lines changed
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ use financial16_25;
2
+
3
+ SELECT
4
+ c .client_id ,
5
+
6
+ sum (amount - payments) as client_balance,
7
+ count (loan_id) as loans_amount
8
+ FROM loan as l
9
+ INNER JOIN
10
+ account a using (account_id)
11
+ INNER JOIN
12
+ disp as d using (account_id)
13
+ INNER JOIN
14
+ client as c using (client_id)
15
+ WHERE True
16
+ AND l .status IN (' A' , ' C' )
17
+ AND d .type = ' OWNER'
18
+ GROUP BY c .client_id
19
+ HAVING
20
+ SUM (amount - payments) > 1000
21
+ AND COUNT (loan_id) > 5
22
+
23
+
24
+ SELECT
25
+ c .client_id ,
26
+
27
+ sum (amount - payments) as client_balance,
28
+ count (loan_id) as loans_amount
29
+ FROM loan as l
30
+ INNER JOIN
31
+ account a using (account_id)
32
+ INNER JOIN
33
+ disp as d using (account_id)
34
+ INNER JOIN
35
+ client as c using (client_id)
36
+ WHERE True
37
+ AND l .status IN (' A' , ' C' )
38
+ AND d .type = ' OWNER'
39
+ -- AND EXTRACT(YEAR FROM c.birth_date) > 1990
40
+ GROUP BY c .client_id
41
+ HAVING
42
+ sum (amount - payments) > 1000
43
+ -- and count(loan_id) > 5
44
+ ORDER BY loans_amount DESC -- tutaj dodajemy sortowanie malejące po liczbie kredytów
You can’t perform that action at this time.
0 commit comments