0% found this document useful (0 votes)
63 views5 pages

SQL Query

The document contains SQL queries to analyze loan data by month, balance transfer details, loan amount buckets by month, average loan size, normal vs balance transfer loans, and disbursement details. The queries group and aggregate the loan data by factors like year, month, loan amount ranges, and balance transfer status to calculate metrics like number of loans, total amount, averages, and percentages.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views5 pages

SQL Query

The document contains SQL queries to analyze loan data by month, balance transfer details, loan amount buckets by month, average loan size, normal vs balance transfer loans, and disbursement details. The queries group and aggregate the loan data by factors like year, month, loan amount ranges, and balance transfer status to calculate metrics like number of loans, total amount, averages, and percentages.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Month_wise_data:-

select year(Disbursement_Date) as 'YEAR',


month(Disbursement_Date) as 'Month',
concat(datename(Month,Disbursement_Date),'-',year(Disbursement_Date)) as Month_Name,
count(App_id) as No_of_Loans,
concat(round(sum(Applied_Amount)/1000000,2),' ','Mn') as Amount ,
concat(round(avg(ROI)*100,2),'%') as Avg_ROI,
concat(round((avg(ROI) * 0.8)*100,2),'%') as Avg_ROI_80 ,
concat(round(Avg(Total_XIRR)*100,1),'%') as Total_XIRR_AVG,
concat(round(Avg(XIRR_80)*100,1),'%') as XIRR_80_AVG
from data_task group by
Year(Disbursement_Date),month(Disbursement_Date),datename(Month,Disbursement_Date) order
by 1,2

select 'GrandTotal' as Grand_Total,COUNT(App_id) as


No_of_Loans,concat(round(sum(Applied_Amount)/1000000,2),' ','Mn') as Amount ,
concat(round(avg(ROI)*100,2),'%') as Avg_ROI,
concat(round((avg(ROI) * 0.8)*100,2),'%') as Avg_ROI_80 ,
concat(round(Avg(Total_XIRR)*100,1),'%') as Total_XIRR_AVG,
concat(round(Avg(XIRR_80)*100,1),'%') as XIRR_80_AVG from data_task

Output:

Month_wise_Balance_Transfer flow:-
select year(Disbursement_Date) as 'YEAR',
month(Disbursement_Date) as 'Month',
concat(datename(Month,Disbursement_Date),'-',year(Disbursement_Date)) as Month_Name,
count(App_id) as No_of_Loans,
concat(round(sum(Applied_Amount)/1000000,1),' ','Mn') as Disb_Amount
from data_task where [BT Yes/No]='Yes' group by
Year(Disbursement_Date),month(Disbursement_Date),datename(Month,Disbursement_Date) order
by 1,2
select 'GrandTotal' as Grand_Total,COUNT(App_id) as
No_of_Loans,round(sum(Applied_Amount)/1000000,1) as Disb_Amount
from data_task where [BT Yes/No]='Yes'

output:
Balance transfer loans wise details

select BT_Name,
count(App_id) as No_of_Loans,
concat(round(sum(Applied_Amount)/1000000,1),' ','Mn') as Disb_Amount
from data_task where [BT Yes/No]='Yes' group by Bt_Name
select 'GrandTotal' as Grand_Total,COUNT(App_id) as
No_of_Loans,concat(round(sum(Applied_Amount)/1000000,1),' ','Mn') as Disb_Amount
from data_task where BT_Name in('Fullerton India Credit Company Limited','idfc first
bank ltd','INCRED FINANCIAL SERVICES LIMITED','Riviera Investors Pvt. Ltd.')
Output:

Bucket_wise_DIsb_Amount:-
use random
go
select * from (select Loan_Buckets,Month_Data,[Applied_Amount] from data_task) ResultSEt
PIVOT
(
SUM([Applied_Amount]) for [Month_Data] IN (
[Aug-2021],[Sep-2021],[Oct-2021],
[Nov-2021],[Dec-2021],[Jan-2022]
)
) as pivottable
select 'GrandTotal' as Grand_Total,concat(round(sum(Applied_Amount)/1000000,1),' ','Mn')
as Disb_Amount
from data_task
select * from (select Loan_Buckets,Month_Data,[App_id] from data_task ) ResultSEt
PIVOT
(
count([App_id]) for [Month_Data] IN (
[Aug-2021],[Sep-2021],[Oct-2021],
[Nov-2021],[Dec-2021],[Jan-2022]
)
) as pivottable
select 'GrandTotal' as Grand_Total,COUNT(App_id) as No_of_Loans
from data_task

Output:-

Avg_Loan_size:
select round(SUM(Applied_Amount)/count(App_id),2) as Average_Loan_size from data_task

Normal loan vs BT Loan:


select count(App_id) as Normal_Loan ,round(SUM(Applied_Amount)/count(App_id),2) as
Normal_Loan_amt from data_task where [BT Yes/No]='No'
select count(App_id) as Normal_Loan ,round(SUM(Applied_Amount)/count(App_id),2) as
Normal_Loan_amt from data_task where [BT Yes/No]='Yes'

Output:
Disbursement_Details:-
select count(App_id) as Disb_Loans ,round(SUM(Applied_Amount/1000000),2) as Disb__amt
from data_task
select count(App_id) as Paid_to_client_Loans ,round(SUM(Paid_to_client/1000000),2) as
Paid__to_client_amt,
(round(SUM(Paid_to_client/1000000)/SUM(Applied_Amount/1000000),4))*100 as amt
from data_task
select count(LPF) as Disb_Loans ,round(SUM(LPF)/1000000,2) as Disb__amt,
(round(SUM(LPF/1000000)/SUM(Applied_Amount/1000000),4))*100 as amt from data_task
select count(Pre_EMI) as Disb_Loans ,round(SUM(Pre_EMI)/1000000,1) as Disb__amt,
(round(SUM(Pre_EMI/1000000)/SUM(Applied_Amount/1000000),4))*100 as amt from data_task
select count(Insurance) as Disb_Loans ,round(SUM(Insurance)/1000000,1),
(round(SUM(Insurance/1000000)/SUM(Applied_Amount/1000000),4))*100 as Disb__amt from
data_task
select count(Balance_transfer) as Disb_Loans ,round(SUM(Balance_transfer/1000000),2) as
Disb__amt
from data_task where [BT Yes/No]='Yes'
select (round(SUM(Balance_transfer/1000000)/SUM(Applied_Amount/1000000),4))*100 as
percentage from data_task

Output:

You might also like