-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank_Loan_Data.sql
More file actions
258 lines (143 loc) 路 7.62 KB
/
Copy pathBank_Loan_Data.sql
File metadata and controls
258 lines (143 loc) 路 7.62 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
--(to fetch total rows and columns of table)--
select * from financial_loan
--(to fetch No. of total loan application of table)--
select count(id)as Total_Loan_Application from financial_loan
--(to fetch total No. of prevoius loan application of table)--
select count(id) as PMTD_Total_loan_application from financial_loan
where MONTH(issue_date)=11 and YEAR(issue_date)=2021
--(to find total funded amount of loan application)--
select sum(loan_amount)as Total_Funded_Amount from financial_loan
--(to find total funded amount of loan application by month to date)--
select sum(loan_amount)as MTDTotal_Funded_Amount from financial_loan
where MONTH(issue_date)=12 and YEAR(issue_date)=2021
--(to find total funded amount of loan application by prevoius month to date)--
select sum(loan_amount)as PMTDTotal_Funded_Amount from financial_loan
where MONTH(issue_date)=11 and YEAR(issue_date)=2021
--(to find total amount received by the customers)--
select sum(total_payment)as Total_Amount_Received from financial_loan
--(to find total amount received month to date by the customers)--
select sum(total_payment)as MTDTotal_Amount_Received from financial_loan
where MONTH(issue_date)=12 and YEAR(issue_date)=2021
--(to find total amount received previous month to date by the customers)--
select sum(total_payment)as PMTDTotal_Amount_Received from financial_loan
where MONTH(issue_date)=11 and YEAR(issue_date)=2021
--(Average Interest Rate)-----------------
select ROUND(AVG(int_rate), 4) * 100 as AVG_INT_RATE from financial_loan
--(Average Interest Rate by MTD)-----------------
select ROUND(AVG(int_rate), 4) * 100 as MTDAVG_INT_RATE from financial_loan
where MONTH(issue_date)=12 and YEAR(issue_date)=2021
--(Average Interest Rate by PMTD)-----------------
select ROUND(AVG(int_rate), 4) * 100 as PMTDAVG_INT_RATE from financial_loan
where MONTH(issue_date)=11 and YEAR(issue_date)=2021
--(Average Dept to income ratio)-----------------
select round(avg(dti),4) * 100 as AVG_DTI from financial_loan
--(Average Dept to income ratio by month do date )-----------------
select round(avg(dti),4) * 100 as MTDAVG_DTI from financial_loan
where MONTH(issue_date)=12 and YEAR(issue_date)=2021
--(Average Dept to income ratio by previous month to date)-----------------
select round(avg(dti),4) * 100 as PMTDAVG_DTI from financial_loan
where MONTH(issue_date)=11 and YEAR(issue_date)=2021
----(Good Loan Application %)----
select loan_status from financial_loan
select (count(case when loan_status = 'Fully Paid' or loan_status = 'Current' then id end )*100)
/
count (id) as Good_Loan_Percentage from financial_loan
----(count of Good Loan Application )----
select count(id) Good_Loan_Applications from financial_loan where loan_status='Fully Paid' or loan_status='Current'
----(Total Good Loan Funded Amount)----
select sum(loan_amount) Good_Loan_Funded_Amount from financial_loan where loan_status='Fully Paid' or loan_status='Current'
----(Total Good Loan Received Amount)----
select sum(total_payment) Good_Loan_Payment_Received from financial_loan where loan_status='Fully Paid' or loan_status='Current'
----(Total Bad Loan Percentage Amount)----
select (count(case when loan_status = 'Charged Off' then id end )*100.0)
/
count (id) as Bad_Loan_Percentage from financial_loan
----(Total Bad Loan Applications)----
select count(id) as Bad_Loan_Applications from financial_loan where loan_status='Charged Off'
----(Total Bad Loan Funded Amount)----
select sum(loan_amount) as Bad_Loan_Funded_Amount from financial_loan where loan_status='Charged Off'
----(Total Bad Loan Amount Received)----
select sum(total_payment) as Bad_Loan_Amount_Received from financial_loan where loan_status='Charged Off'
----(Total_Loan_Aplications,Amount_Received,Funded_Amount, Interest_Rate and DTI)----
select loan_status,
count(id) as Total_Loan_Aplications,
sum(total_payment) as Total_Amount_Received,
sum(loan_amount) as Total_Funded_Amount,
avg(int_rate * 100) as Interest_Rate,
avg(dti * 100) as DTI from financial_loan group by loan_status
----(MTD_Total_Amount_Received,MTD_Total_Funded_Amount)----
select loan_status,
sum(total_payment) as MTD_Total_Amount_Received,
sum(loan_amount)as MTD_Total_Funded_Amount
from financial_loan where MONTH(issue_date)=12 group by loan_status
----(Total_Loan_Applications,Total_Funded_Amount,Total_Received_Amount)----
select MONTH(issue_date) as Month_Number,
DATENAME(month,issue_date) as Month_Name ,
count(id) as Total_Loan_Applications,
sum(loan_amount) as Total_Funded_Amount,
sum(total_payment) as Total_Received_Amount
from financial_loan group by DATENAME(month,issue_date),MONTH(issue_date)
order by MONTH(issue_date)
----(Total_Loan_Applications,Total_Funded_Amount,Total_Received_Amount)----
select address_state,
count(id) as Total_Loan_Applications,
sum(loan_amount) as Total_Funded_Amount,
sum(total_payment) as Total_Received_Amount
from financial_loan group by address_state
order by sum(loan_amount) desc
----(Total_Loan_Applications,Total_Funded_Amount,Total_Received_Amount order by count id)----
select address_state,
count(id) as Total_Loan_Applications,
sum(loan_amount) as Total_Funded_Amount,
sum(total_payment) as Total_Received_Amount
from financial_loan group by address_state
order by count(id) desc
----(Total_Loan_Applications,Total_Funded_Amount,Total_Received_Amount order by term)----
select term,
count(id) as Total_Loan_Applications,
sum(loan_amount) as Total_Funded_Amount,
sum(total_payment) as Total_Received_Amount
from financial_loan group by term
order by term
----(Total_Loan_Applications,Total_Funded_Amount,Total_Received_Amount order by emp_length)----
select emp_length,
count(id) as Total_Loan_Applications,
sum(loan_amount) as Total_Funded_Amount,
sum(total_payment) as Total_Received_Amount
from financial_loan group by emp_length
order by emp_length
----(Total_Loan_Applications,Total_Funded_Amount,Total_Received_Amount order by count id)----
select emp_length,
count(id) as Total_Loan_Applications,
sum(loan_amount) as Total_Funded_Amount,
sum(total_payment) as Total_Received_Amount
from financial_loan group by emp_length
order by count (id) desc
----(Total_Loan_Applications,Total_Funded_Amount,Total_Received_Amount group by purpose)----
select purpose,
count(id) as Total_Loan_Applications,
sum(loan_amount) as Total_Funded_Amount,
sum(total_payment) as Total_Received_Amount
from financial_loan group by purpose
order by count (id) desc
----(Total_Loan_Applications,Total_Funded_Amount,Total_Received_Amount group by home ownership)----
select home_ownership,
count(id) as Total_Loan_Applications,
sum(loan_amount) as Total_Funded_Amount,
sum(total_payment) as Total_Received_Amount
from financial_loan group by home_ownership
order by count (id) desc
----(Total_Loan_Applications,Total_Funded_Amount,Total_Received_Amount by grade 'A')----
select home_ownership,
count(id) as Total_Loan_Applications,
sum(loan_amount) as Total_Funded_Amount,
sum(total_payment) as Total_Received_Amount
from financial_loan where grade='A' group by home_ownership
order by count (id) desc
----(Total_Loan_Applications,Total_Funded_Amount,Total_Received_Amount by grade 'A' and Address_State='CA')----
select home_ownership,
count(id) as Total_Loan_Applications,
sum(loan_amount) as Total_Funded_Amount,
sum(total_payment) as Total_Received_Amount
from financial_loan where grade='A' and address_state='CA' group by home_ownership
order by count (id) desc