Using the BANK database write and execute the following SQL queries

Questions & Answers

Using the BANK database write and execute the following SQL queries:

1. Write a query in SQL to display the customer_name(fname, Iname) whose acc_status is “Active”.

SELECT fname, Iname
FROM customer
WHERE acc_status = 'Active';

2. Write a query in SQL to display the customer_name (fname, lname) who takes the loan from the Irbid branch.

SELECT fname, Iname
FROM customer
JOIN loan ON customer.cust_id = loan.cust_id
JOIN branch ON loan.branch_id = branch.branch_id
WHERE branch.branch_name = 'Irbid';

3. Write a query in SQL to display the total loan amount for each branch.

SELECT branch_name, SUM(loan_amount) AS total_loan_amount
FROM loan
JOIN branch ON loan.branch_id = branch.branch_id
GROUP BY branch_name;

4. Write a query in SQL to display the Maximum, Minimum, and total balance for each account type.

SELECT account_type, MAX(balance) AS maximum_balance, MIN(balance) AS minimum_balance, SUM(balance) AS total_balance
FROM account
GROUP BY account_type;

5. Write a query in SQL to display the cust_id, fname, and city for each customer when your balance is less than total amount of loans.

SELECT customer.cust_id, fname, city
FROM customer
JOIN account ON customer.cust_id = account.cust_id
JOIN loan ON customer.cust_id = loan.cust_id
WHERE account.balance < loan.loan_amount;

Leave a Comment