Question

Consider the schema below that models a bank’s branches, customers and their accounts and loans. Provide...

Consider the schema below that models a bank’s branches, customers and their accounts and loans. Provide SQL queries to answer the questions that follow.

Branch (bank_name, addr, city, assets) // Primary Key=bank_name

Customer (cust_name, addr, city) // Primary Key=cust_name

Account (acc_num, cust_name, bank_name, type, balance) // Primary Key=acc_num

Loan (loan_num, cust_name, bank_name, type, amount)  // Primary Key=loan_num

*****Use a nested subquery if possible*****

-- 3.   Find the bank with the largest total account balance, i.e., the bank

--    that has the most funds in accounts with it.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SELECT bank_name FROM Branch WHERE

(SELECT MAX
(
(SELECT SUM(balance) FROM Account WHERE Branch.bank_name = Account.bank_name)
-
(SELECT SUM(amount) FROM Loan WHERE Branch.bank_name = Loan.bank_name)
)
AS Total_Fund
) 

Here I have indented the query into different lines so that it would be easy to understand

First of all, I have selected the bank name from the branch and then I have nested two subqueries to find the difference between the sum of the account balance and sum of all loans and them find the maximum from the difference that was generated from the two subqueries.

I hope that you can understand what I want to explain.

Add a comment
Know the answer?
Add Answer to:
Consider the schema below that models a bank’s branches, customers and their accounts and loans. Provide...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the schema below that models a bank’s branches, customers and their accounts and loans. Provide...

    Consider the schema below that models a bank’s branches, customers and their accounts and loans. Provide SQL queries to answer the questions that follow. Branch (bank_name, addr, city, assets) // Primary Key=bank_name Customer (cust_name, addr, city) // Primary Key=cust_name Account (acc_num, cust_name, bank_name, type, balance) // Primary Key=acc_num Loan (loan_num, cust_name, bank_name, type, amount)  // Primary Key=loan_num -- 2. Find the names of all the customers who live in a city with no bank branches. -- a) Use a nested subquery....

  • 1. Explain total participation and partial participation in ER diagram. 2. Explain disjointness constraints and co...

    1. Explain total participation and partial participation in ER diagram. 2. Explain disjointness constraints and completeness constraints in EER modeling. 3. Map the following conceptual schema in ER to logical database schema 1 1Page 11 BANK-BRANCH BANK BRANCHES> Branch no Addr CodeNameAddr LOANS ACCTS Loan no Amount Acct no Balance Type LOAN Type ACCOUNT L_C AC Name Ssn CUSTOMER Phone 1. Explain total participation and partial participation in ER diagram. 2. Explain disjointness constraints and completeness constraints in EER modeling....

  • Let us use the conceptual schema diagram below to answer the question parts. It is about...

    Let us use the conceptual schema diagram below to answer the question parts. It is about a database for banks and their branches. BANK HAS BANK BRANCH Code Name Addr Addr Branch_no Acct_no Loan_no ISSUES ACCTS ISSUES LOANS Balance Type Type Amount 0: n 0: n Name Phone CUSTOMER Addr Ssn

  • This is how i mapped the relational schema diagram. would this be correct? i feel like...

    This is how i mapped the relational schema diagram. would this be correct? i feel like i am missing something. ud bundle at the start of the class on the due date. ment. 1. (10 pts) Use the ER-to-relational mapping algorithm to map the BANK ER diagram to a relational schema diagram. Prepare the diagram using ERDPlus and make sure to specify all primary keys and foreign keys. (Position the relations so that the arcs from the foreign keys to...

  • Write SQL statements to answer the following questions using Assignment 3’s schema (tables from part 1)....

    Write SQL statements to answer the following questions using Assignment 3’s schema (tables from part 1). 1- Find how many branches had have loans over $2000.00. 2- For each branch, find the most expensive loan. Your output should include Branch Id, loan amount for the highest loan for that Branch. 3- Find how many accounts there are for each customer. The output should include customer id and number of accounts for that customer. 4- Find the total balance amount of...

  • Write the following queries in Relational Algebra, for the following bank schema: account (ano, bname, balance)...

    Write the following queries in Relational Algebra, for the following bank schema: account (ano, bname, balance) branch (bname, bcity, assest) customer (Cname, cstreet, ccity) loan (lno, bname, amount) deposit (cname, ano) borrower (cname, ino) -Select all loan tuples where branch name is Abha. -Select all loan tuples where branch name is Abha and loan amount less than 200000.   Please type the solution on the keyboard so that I can copy and paste

  • Consider the bank database of Figure 5.25. Write an SQL trigger to carry out the following...

    Consider the bank database of Figure 5.25. Write an SQL trigger to carry out the following action: On delete of an account, for each owner of the account, check if the owner has any remaining accounts, and if she does not, deleteher from the depositor relation branch(branch name, branch city, assets) customer (customer name, customer street, cust omer city) loan (loan number, branch name, amount) borrower (customer name, loan number) a ccount (account number, branch name, balance ) depositor (customer...

  • Need the SQL query for the questions below 1) Print the name of customers who do...

    Need the SQL query for the questions below 1) Print the name of customers who do not live in MPLS or Edina, have a loan with an amount of more than 500 in any branch of the bank but not in the France branch, and have one or more accounts only in the France branch. 2) Show the name of all Customers who have only one account with a balance of more than $1000 in any branch of the bank...

  • For the below `bank' schema: customer(customerid,username,fname,lname,street1,street2,city,state,zip) account(accountid,customerid,description,) transaction(transactionid,trantimestamp,accountid,amount) A customer may have several accounts, and each...

    For the below `bank' schema: customer(customerid,username,fname,lname,street1,street2,city,state,zip) account(accountid,customerid,description,) transaction(transactionid,trantimestamp,accountid,amount) A customer may have several accounts, and each account may participate in many transactions. Each transaction will have at least two records, one deducting amount from an account, and one adding amount to an account (for a single transactionid, the sum of amounts will equal zero). Using SQL, answer these questions (write a SQL query that answers these questions): 8) List the top 1% of customers (ordered by total balance). 9) Using...

  • Problem 1) Banking Application Consider the application domain of a banking application where you have customers...

    Problem 1) Banking Application Consider the application domain of a banking application where you have customers who have one or more accounts of type Checking or Saving. Some of the customers may also have one or more loans that they have taken from the bank. Each loan has a borrowed amount and current balance amount. Loan may be either outstanding or paid off. Questions 1. Create a Conceptual model (List Entities and note Relationships, 2- 3 Relationships only) (3 Pts)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT