-
Notifications
You must be signed in to change notification settings - Fork 1
/
Statistics_sql_code.sql
45 lines (40 loc) · 1.05 KB
/
Statistics_sql_code.sql
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
40
41
42
43
44
45
-- Loan Insight: Average Loan Price per country sorted in descending order
select
trunc(avg(loan_amount)) as average_loan,
country_name
from loan
group by
country_name
order by
avg(loan_amount) desc
-- Insights on Loans and Lenders : Most common sectors and activities for loan use
select
sector_name,
activity_name,
trunc(avg(lender_term)) as average_lender_term_in_months,
count(sector_name) as Count_of_loans,
trunc(avg(loan_amount)) as Average_loan
from loan
group by
sector_name,
activity_name
order by
count(sector_name) desc
-- Insights on Loans and Lenders: Average numbers of lenders per loan grouped by sector and activity
select
trunc(avg(a.count_of_lenders)) as average_lenders_per_loan,
b.sector_name,
b.activity_name
from (
SELECT
loan_id,
LENGTH(lenders) - LENGTH(REPLACE(lenders, ' ', '')) + 1 as Count_of_lenders
FROM loan_lender
order by
count_of_lenders desc
) a
inner join loan b on a.loan_id = b.id
group by
b.sector_name,
b.activity_name
order by average_lenders_per_loan desc