1.
Branches with Most customer
(Write a query to show the branch name,branch city where we have the maximum customers. For
example the branch B00019 has 3 customers, B00020 has 7 and B00021 has 10. So branch id B00021
is having maximum customers. If B00021 is Koramangla branch Bangalore, Koramangla branch should
be displayed along with city name Bangalore. In case of multiple records, display the records sorted in
ascending order based on branch name)
SELECT b.branch_name,b.branch_city FROM branch_master b
JOIN account_master a ON b.branch_id = a.branch_id
GROUP BY b.branch_city,b.branch_name
HAVING count(a.customer_number)>=all(SELECT count(a.customer_number)
FROM branch_master b
JOIN account_master a ON b.branch_id=a.branch_id
GROUP BY b.branch_name)
ORDER BY b.branch_name;
------or------
SELECT b.branch_name,b.branch_city FROM branch_master b
JOIN account_master a ON b.branch_id = a.branch_id
GROUP BY b.branch_name
ORDER BY b.branch_name,count(a.customer_number) desc limit 1;
2. Customer details based on Date
(Write a query to display the customer number, customer firstname,account number for the
customer’s whose accounts were created after 15th of any month. Display the records sorted in
ascending order based on customer number and then by account number.)
SELECT A.customer_number, A.firstname, B.account_number FROM customer_master A
JOIN account_master B USING ( customer_number )
WHERE day(B.account_opening_date) > 15
ORDER BY A.customer_number, B.account_number;
------or------
SELECT c.customer_number, c.firstname, a.account_number FROM customer_master c
JOIN account_master a ON c.customer_number=a.customer_number
WHERE day(a.account_opening_date) > 15
ORDER BY c.customer_number, a.account_number;
3. Customer Name with Account Details
(Write a query to display account number, customer’s number, customer’s firstname, lastname,
account opening date. Display the records sorted in ascending order based on account number)
SELECT a.account_number, a.customer_number, c.firstname, c.lastname, a.account_opening_date
FROM account_master a
JOIN customer_master c on c.customer_number=a.customer_number
ORDER BY a.account_number;
------or------
SELECT B.account_number, A.customer_number, A.firstname, A.lastname, B.account_opening_date
FROM customer_master A
JOIN account_master B USING ( customer_number)
ORDER BY B.account_number;
4. Customer without Accounts
(Write a query to display the number of customers who have registration but no account in the
bank. Give the alias name as Count_Customer for number of customers)
SELECT count(customer_number) as Count_Customer FROM customer_master
WHERE customer_number NOT IN ( SELECT DISTINCT customer_number FROM account_master);
5. Total Customers from Delhi
(Write a query to display the number of customer’s from Delhi. Give the count an alias name of
Cust_Count)
SELECT count(customer_city) as Cust_Count FROM customer_master
WHERE customer_city='Delhi';
6. Total Transaction Done
(Write a query to display the total number of withdrawals and total number of deposits being done
by customer whose customer number ends with 001. The query should display transaction type and
the number of transactions. Give an alias name as Trans_Count for number of transactions. Display
the records sorted in ascending order based on transaction type)
SELECT A.transaction_type, count(A.transaction_number) as Trans_Count FROM transaction_details
A
JOIN account_master B USING(account_number)
WHERE B.customer_number LIKE '%001'
GROUP BY A.transaction_type
ORDER BY A.transaction_type;
------or------
SELECT t.transaction_type, count(t.transaction_number) as Trans_Count FROM transaction_details t
JOIN account_master a ON a.account_number=t.account_number
WHERE a.customer_number LIKE '%001'
GROUP BY t.transaction_type
ORDER BY t.transaction_type;