USE this part to write SQL statements   Branch(branch_id:integer, branch_name:varchar(50), branch_location:varchar(40), money_on_hand:numeric(15,2)       create table Branch             (branch_id                              integer,     branch_name                                 varchar(50),     branch_location                 varchar(40),     money_on_hand                 numeric(15,2),     primary key (branch_id));   Loan(loan_number:integer, branch_id:integer, amount:numeric(8,2))                   foreign key branch_id references Branch(branch_id)   create table Loan       (loan_number            integer,     branch_id                                  integer,     amount                                     numeric(8,2),     primary key (loan_number),     foreign key (branch_id) references Branch (branch_id));   Customer(customer_id:integer, customer_last_name:varchar(35),customer_first_name:varchar(25), customer_street:varchar(30), customer_zip:integer)       create table Customer             (customer_id              integer,     customer_last_name          varchar(35),     customer_first_name         varchar(25),     customer_street                 varchar(30),     customer_zip                      integer,     primary key (customer_id));   Borrower(customer_id:integer, loan_number:integer) foreign key (customer_id) references Customer(customer_id) foreign key (loan_number) references Loan(loan_number)   create table Borrower       (customer_id              integer,     loan_number                            integer,     primary key (customer_id, loan_number),     foreign key (customer_id) references Customer (customer_id),     foreign key (loan_number) references Loan (loan_number));   Depositor(customer_id:integer, account_number:integer) foreign key (customer_id) references Customer(customer_id) foreign key (account_number) references Account(account_number)   Note: as the Account table is a referenced table, you have to create that table first.   create table Depositor       (customer_id              integer,     account_number                      integer,     primary key (customer_id, account_number),     foreign key (customer_id) references Customer (customer_id),     foreign key (account_number) references Account (account_number));   Account(account_number:integer, branch_id:integer, balance:numeric(8,2)) foreign key branch_id references Branch(branch_id)   create table Account       (account_number                  integer,     branch_id                                  integer,     balance                                     numeric(8,2),     primary key (account_number),     foreign key (branch_id) references Branch (branch_id));   Write SQL statements to answer the following questions using Assignment 3’s schema (tables from part 1).  You can add more data to the tables if you want, just follow the PK and FK rules.  Accounts are not Loans and Loans are not Accounts.   1- Find how many branches have loans between $4,100.00 and $7,000.00.  HINT: Do not manually count the rows, have the DBMS engine do the work.   2- For each branch, find the Min and Max loan amounts. Your output should include Branch Id, min loan amount and max loan amount 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 average account balance for each Branch. The output should be a list of Branch Id and for each Branch Id, the average account balance in that Branch.   5- Find Customer ID, Customer name and Customer City for all accounts, sorted by Customer City, then Customer Last name.   6- Find Customer ID, Customer name and the number of loans for each Customer.   7- Find Loan number and Customer Id of the loan with the lowest amount.   8- Create a view called Gary_Branch_V that contains Branch Id, Branch name, and number of loans for each Branch that is in the city of Gary.   9- For each Customer in Hopkins, find the balance in their account(s).      10- Find how many different accounts each customer has at each Branch. The output should be a list of Customer ID and for each Customer ID, the number of accounts for this customer by Branch ID.   11- Find the branch with the highest or largest Average loan amount.  List the Branch ID, Branch Name, and the Highest Average loan amount.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

USE this part to write SQL statements

 

  1. Branch(branch_id:integer, branch_name:varchar(50), branch_location:varchar(40), money_on_hand:numeric(15,2)

 

    create table Branch

            (branch_id                              integer,

    branch_name                                 varchar(50),

    branch_location                 varchar(40),

    money_on_hand                 numeric(15,2),

    primary key (branch_id));

 

  1. Loan(loan_number:integer, branch_id:integer, amount:numeric(8,2))

                  foreign key branch_id references Branch(branch_id)

 

create table Loan

      (loan_number            integer,

    branch_id                                  integer,

    amount                                     numeric(8,2),

    primary key (loan_number),

    foreign key (branch_id) references Branch (branch_id));

 

  1. Customer(customer_id:integer, customer_last_name:varchar(35),customer_first_name:varchar(25), customer_street:varchar(30), customer_zip:integer)

 

    create table Customer

            (customer_id              integer,

    customer_last_name          varchar(35),

    customer_first_name         varchar(25),

    customer_street                 varchar(30),

    customer_zip                      integer,

    primary key (customer_id));

 

  1. Borrower(customer_id:integer, loan_number:integer)

foreign key (customer_id) references Customer(customer_id)

foreign key (loan_number) references Loan(loan_number)

 

create table Borrower

      (customer_id              integer,

    loan_number                            integer,

    primary key (customer_id, loan_number),

    foreign key (customer_id) references Customer (customer_id),

    foreign key (loan_number) references Loan (loan_number));

 

  1. Depositor(customer_id:integer, account_number:integer)

foreign key (customer_id) references Customer(customer_id)

foreign key (account_number) references Account(account_number)

 

Note: as the Account table is a referenced table, you have to create that table first.

 

create table Depositor

      (customer_id              integer,

    account_number                      integer,

    primary key (customer_id, account_number),

    foreign key (customer_id) references Customer (customer_id),

    foreign key (account_number) references Account (account_number));

 

  1. Account(account_number:integer, branch_id:integer, balance:numeric(8,2))

foreign key branch_id references Branch(branch_id)

 

create table Account

      (account_number                  integer,

    branch_id                                  integer,

    balance                                     numeric(8,2),

    primary key (account_number),

    foreign key (branch_id) references Branch (branch_id));

 

Write SQL statements to answer the following questions using Assignment 3’s schema (tables from part 1).  You can add more data to the tables if you want, just follow the PK and FK rules.  Accounts are not Loans and Loans are not Accounts.

 

1- Find how many branches have loans between $4,100.00 and $7,000.00.  HINT: Do not manually count the rows, have the DBMS engine do the work.

 

2- For each branch, find the Min and Max loan amounts. Your output should include Branch Id, min loan amount and max loan amount 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 average account balance for each Branch. The output should be a list of Branch Id and for each Branch Id, the average account balance in that Branch.

 

5- Find Customer ID, Customer name and Customer City for all accounts, sorted by Customer City, then Customer Last name.

 

6- Find Customer ID, Customer name and the number of loans for each Customer.

 

7- Find Loan number and Customer Id of the loan with the lowest amount.

 

8- Create a view called Gary_Branch_V that contains Branch Id, Branch name, and number of loans for each Branch that is in the city of Gary.

 

9- For each Customer in Hopkins, find the balance in their account(s).   

 

10- Find how many different accounts each customer has at each Branch. The output should be a list of Customer ID and for each Customer ID, the number of accounts for this customer by Branch ID.

 

11- Find the branch with the highest or largest Average loan amount.  List the Branch ID, Branch Name, and the Highest Average loan amount.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education