0% found this document useful (0 votes)
72 views16 pages

BMS Schema

This document contains 25 SQL queries on various tables in a banking database schema including account_master, customer_master, transaction_details, branch_master, and loan_details tables. The queries select, filter, group, join, and aggregate data from these tables to return customer information, account information, transaction details, branch details, and more.

Uploaded by

ind sh1
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)
72 views16 pages

BMS Schema

This document contains 25 SQL queries on various tables in a banking database schema including account_master, customer_master, transaction_details, branch_master, and loan_details tables. The queries select, filter, group, join, and aggregate data from these tables to return customer information, account information, transaction details, branch details, and more.

Uploaded by

ind sh1
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/ 16

BMS SCHEMA

1
select account_number, account_master.customer_number,
FIRSTNAME,lastname,account_opening_date from account_master,customer_master
where customer_master.customer_number = account_master.customer_number order by
account_number;

2.
select count(*) as Cust_Count from branch_master where branch_city = 'Delhi';
3.
select customer_master.customer_number, firstname,account_number from
customer_master inner join account_master on customer_master.customer_number =
account_master.customer_number where day(account_opening_date) between 15 and 31
order by customer_number,account_number ;
4.
SELECT am.customer_number,firstname, account_number
FROM customer_master as cm INNER JOIN account_master as am ON
cm.customer_number=am.customer_number WHERE account_status='Terminated'
ORDER BY am.customer_number, account_number;

5.
SELECT transaction_type,count(transaction_number) as Trans_Count
FROM account_master as am INNER JOIN transaction_details as td
ON am.account_number=td.account_number
WHERE customer_number like '%001' ORDER BY transaction_type;
6.
SELECT count(customer_number) as Count_Customer
from customer_master
WHERE customer_number NOT IN (SELECT customer_number FROM account_master);
7.
SELECT td.account_number, opening_balance+sum(transaction_amount) as
Deposit_Amount FROM account_master as am INNER JOIN transaction_details as td
ON am.account_number=td.account_number WHERE transaction_type='deposit'
GROUP BY account_number ORDER BY account_number;

8.
select branch_master.branch_city, count(account_master.account_number) as
No_of_Accounts from branch_master left join account_master on
account_master.branch_id=branch_master.branch_id
group by branch_master.branch_city order by branch_city;
9.
select firstname FROM customer_master cm INNER JOIN account_master am ON
cm.customer_number=am.customer_number
group by firstname having count(account_number)>1 order by firstname;
10.
SELECT ld.customer_number, firstname, lastname
FROM customer_master as cm INNER JOIN loan_details as ld
ON cm.customer_number=ld.customer_number
GROUP BY customer_number having count(branch_id)>1 ORDER BY customer_number;

11.
select customer_master.customer_number, firstname, customer_city, branch_city
from account_master inner join customer_master on account_master.customer_number =
customer_master.customer_number
inner join branch_master on account_master.branch_id = branch_master.branch_id
where customer_city != branch_city order by customer_master.customer_number;
12.
SELECT count(ld.customer_number) Count
FROM customer_master as cm INNER JOIN loan_details AS ld
ON cm.customer_number=ld.customer_number
WHERE cm.customer_number NOT IN ( SELECT customer_number FROM account_master);

13.
SELECT td.account_number
FROM account_master AS am INNER JOIN transaction_details td
ON am.account_number=td.account_number group by td.account_number
having count(td.transaction_number)>=ALL(SELECT count(td.transaction_number)
FROM account_master AS am INNER JOIN transaction_details AS td
ON am.account_number=td.account_number group by td.account_number ) order by
am.account_number;

14.
select branch_name,branch_city
FROM branch_master INNER JOIN account_master
ON branch_master.branch_id=account_master.branch_id
group by branch_name having count(customer_number)>=ALL
(select count(customer_number) FROM branch_master INNER JOIN account_master
ON branch_master.branch_id=account_master.branch_id group by branch_name) order by
branch_name;
15.
select am.account_number,opening_balance+sum(case when transaction_type='Deposit'
then transaction_amount end) as Deposit,sum(case when transaction_type='withdrawal'
then
transaction_amount end) as Withdrawal from account_master am join transaction_details
td on am.account_number=td.account_number group by am.account_number having
Withdrawal>Deposit;
16.
SELECT (SUM(CASE WHEN transaction_type='Deposit'
THEN transaction_amount END)) -(SUM(CASE WHEN transaction_type='Withdrawal'
THEN transaction_amount END))+(select opening_balance from account_master where
account_number like '%001') AS Balance_Amount
FROM transaction_details where account_number like '%001';

17.
SELECT cm. customer_number,firstname, am.account_number,count(transaction_number)
Count_Trans
FROM customer_master cm inner JOIN account_master am
ON cm.customer_number=am.customer_number INNER JOIN transaction_details td
ON am.account_number=td.account_number group by am.account_number order by
cm.customer_number, am.account_number;
18.
SELECT firstname FROM customer_master INNER JOIN account_master
ON customer_master.customer_number=account_master.customer_number
GROUP BY firstname having count(firstname)>=2 order by firstname;
19.
SELECT ld.customer_number, firstname, lastname FROM customer_master cm INNER JOIN
loan_details as ld ON cm.customer_number=ld.customer_number group by
customer_number having count(branch_id)>=2 and sum(loan_amount)>=All(select
sum(loan_amount) from loan_details group by customer_number);

20.
SELECT ld.customer_number, firstname,branch_id, loan_amount FROM customer_master
cm INNER JOIN loan_details ld ON cm.customer_number=ld.customer_number order by
cm.customer_number, branch_id, loan_amount;
21.
SELECT branch_city, count(branch_id) Count_Branch FROM branch_master GROUP BY
branch_city ORDER BY branch_city;

22.
SELECT account_number, firstname, lastname FROM customer_master cm INNER JOIN
account_master am ON cm.customer_number=am.customer_number
WHERE account_status='Active' ORDER BY account_number;
23.
SELECT customer_number,firstname,coalesce(middlename,lastname) Middle_Name
FROM customer_master order by customer_number;

24.
SELECT customer_number,firstname,customer_date_of_birth
FROM customer_master order by year(customer_date_of_birth), firstname;
25.
SELECT firstname, customer_city,account_number FROM customer_master cm INNER JOIN
account_master am ON cm.customer_number=am.customer_number WHERE occupation !
='Service' and occupation != 'Student' and occupation != 'Business' order by firstname,
account_number;

You might also like