0% found this document useful (0 votes)
179 views9 pages

25 Query Question

The document contains SQL statements to create tables and insert data for customers, branches, accounts, loans, and borrowers for a bank database. The tables are then queried to return various data points, such as names and cities of borrowers, accounts within a certain balance range, customers on streets ending in "Hill", and more. Thirteen queries are run on the tables to retrieve requested information.
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)
179 views9 pages

25 Query Question

The document contains SQL statements to create tables and insert data for customers, branches, accounts, loans, and borrowers for a bank database. The tables are then queried to return various data points, such as names and cities of borrowers, accounts within a certain balance range, customers on streets ending in "Hill", and more. Thirteen queries are run on the tables to retrieve requested information.
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/ 9

25 Query

#########################################################################

Customer Depositor
CUSTOME CUSTOMER_ CUSTOME CUSTOMER_N ACCOUNT_NUMB
R_NAME STREET R_CITY AME ER
Adams Spring Pittsfield Johnson A-101
Brooks Senator Brooklyn Smith A-215
Curry North Rye Hayes A-102
Glenn Sand Hill Woodside Turner A-305
Green Walnut Stamford Johnson A-201
Hayes Main Harrison Jones A-217
Johnson Alma Palo Alto Lindsay A-222
Jones Main Harrison
Smith Main Rye
Turner Putnam Stamford
Williams Nassau Princeton

Account Borrower
ACCOUN CUSTOMER_NA LOAN_NUMBE
T_NUMB BRANCH_ ME R
ER NAME BALANCE Jones L-17
A-101 Downtown 500 Smith L-23
A-215 Mianus 700 Hayes L-15
A-102 Perryridge 400 Jackson L-14
A-305 Round Hill 350 Curry L-93
A-201 Perryridge 900 Smith L-11
A-222 Redwood 700 Williams L-17
A-217 Brighton 750 Adams L-16

Loan Branch
LOAN_NU BRANCH_NA AMOUN BRANCH_N BRANCH_
MBER ME T AME CITY ASSETS
L-17 Downtown 1000 Downtown Brooklyn 900000
L-23 Redwood 2000 Redwood Palo Alto 2100000
L-15 Perryridge 1500 Perryridge Horseneck 1700000
L-14 Downtown 1500 Mianus Horseneck 400200
L-93 Mianus 500 Round Hill Horseneck 8000000
L-11 Round Hill 900 Pownal Bennington 400000
L-16 Perryridge 1300 North Town Rye 3700000
Brighton Brooklyn 7000000

# CREATE TABLE "customer" AND INSERT DATA:


-----------------------------------------
create table customer (
Customer_name varchar(15),
Customer_street varchar(15),
Customer_city varchar(15)
);

insert into customer values('Adams','Spring','Pittsfield');


insert into customer values('Brooks','Senator','Brooklyn');
insert into customer values('Curry','North','Rye');
insert into customer values('Glenn','Sand Hill','Woodside');
insert into customer values('Green','Walnut','Stamford');
insert into customer values('Hayes','Main','Harrison');
insert into customer values('Johnson','Alma','Palo Alto');
insert into customer values('Jones','Main','Harrison');
insert into customer values('Smith','Main','Rye');
insert into customer values('Turner','Putnam','Stamford');
insert into customer values('Williams','Nassau','Princeton');

# CREATE TABLE "branch" AND INSERT DATA:


-----------------------------------------
create table branch (
Branch_name varchar(12),
Branch_city varchar(12),
Assets number
);

insert into branch values('Downtown','Brooklyn',900000);


insert into branch values('Redwood','Palo Alto',2100000);
insert into branch values('Perryridge','Horseneck',1700000);
insert into branch values('Mianus','Horseneck',400200);
insert into branch values('Round Hill','Horseneck',8000000);
insert into branch values('Pownal','Bennington',400000);
insert into branch values('North Town','Rye',3700000);
insert into branch values('Brighton','Brooklyn',7000000);

# CREATE TABLE "account" AND INSERT DATA:


-----------------------------------------
create table account (
Account_number varchar(15),
Branch_name varchar(12),
Balance number
);

insert into account values('A-101','Downtown',500);


insert into account values('A-215','Mianus',700);
insert into account values('A-102','Perryridge',400);
insert into account values('A-305','Round Hill',350);
insert into account values('A-201','Perryridge',900);
insert into account values('A-222','Redwood',700);
insert into account values('A-217','Brighton',750);

# CREATE TABLE "depositor" AND INSERT DATA:


-----------------------------------------
create table depositor (
Customer_name varchar(15),
Account_number varchar(15)
);

insert into depositor values('Johnson','A-101');


insert into depositor values('Smith','A-215');
insert into depositor values('Hayes','A-102');
insert into depositor values('Turner','A-305');
insert into depositor values('Johnson','A-201');
insert into depositor values('Jones','A-217');
insert into depositor values('Lindsay','A-222');

# CREATE TABLE "loan" AND INSERT DATA:


-----------------------------------------

create table loan(


Loan_number varchar(12),
Branch_name varchar(12),
Amount number
);

insert into loan values('L-17','Downtown',1000);


insert into loan values('L-23','Redwood',2000);
insert into loan values('L-15','Perryridge',1500);
insert into loan values('L-14','Downtown',1500);
insert into loan values('L-93','Mianus',500);
insert into loan values('L-11','Round Hill',900);
insert into loan values('L-16','Perryridge',1300);

# CREATE TABLE "borrower" AND INSERT DATA:


-----------------------------------------
create table borrower(
Customer_name varchar(15),
Loan_number varchar(12)
);

insert into borrower values('Jones','L-17');


insert into borrower values('Smith','L-23');
insert into borrower values('Hayes','L-15');
insert into borrower values('Jackson','L-14');
insert into borrower values('Curry','L-93');
insert into borrower values('Smith','L-11');
insert into borrower values('Williams','L-17');
insert into borrower values('Adams','L-16');

#01. Find the names & cities of all borrowers


""""""""""""""""""""""""""""""""""""""""""""""

CUSTOMER_NAME CUSTOMER_CITY
Jones Harrison
Smith Rye
Hayes Harrison
Curry Rye
Williams Princeton
Adams Pittsfield

#02. Set of names & cities of customers who have a loan at "Perryridge" branch
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
CUSTOMER_NAME CUSTOMER_CITY
Adams Pittsfield
Hayes Harrison

#03. Number of accounts with balance between 700 and 900


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""

ACCOUNT_NUMBER BALANCE
A-215 700
A-201 900
A-222 700
A-217 750
#04. Name of customers on streets with names ending in "Hill"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
CUSTOMER_NAME CUSTOMER_STREET
Glenn Sand Hill

#05. Name of customers with both accounts and loans at "Perryridge" branch
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
CUSTOMER_NAME
Hayes

#06. Names of customers with an account but not a loan at "Perryridge" branch
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
CUSTOMER_NAME
Johnson

#07. Names & cities of all borrowers


"""""""""""""""""""""""""""""""""""""
CUSTOMER_NAME CUSTOMER_CITY
Jones Harrison
Smith Rye
Hayes Harrison
Curry Rye
Williams Princeton
Adams Pittsfield

#08. Set of names of customers with accounts at a branch where "Hayes" has an account
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
CUSTOMER_NAME
Hayes
Johnson
#09. Set of names of branch whose assets are greater than the Assets of some branch in
"Brooklyn"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
BRANCH_NAME ASSETS
Redwood 2100000
Perryridge 1700000
Round Hill 8000000
North Town 3700000
Brighton 7000000
#10. Set of names of branch whose assets are greater than the Assets of all branch in
"Brooklyn"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
BRANCH_NAME ASSETS
Round Hill 8000000

#11. Set of names of customers at "Perryridge" branch in alphabetical order


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
CUSTOMER_NAME
Adams
Hayes
Johnson
#12. Loan data ordered by decreasing ammount then increasing loan numbers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
LOAN_NUMBER BRANCH_NAME AMOUNT
L-23 Redwood 2000
L-14 Downtown 1500
L-15 Perryridge 1500
L-16 Perryridge 1300
L-17 Downtown 1000
L-11 Round Hill 900
L-93 Mianus 500

#13. Names of branch having at least one account with average account balance
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
BRANCH_NAME AVG(BALANCE)
Round Hill 350
Mianus 700
Perryridge 650
Redwood 700
Brighton 750
Downtown 500

#14. Names of branch having at least one account with size of set of customers having at least
one account at that branch
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
BRANCH_NAME COUNT(ACCOUNT_NUMBER)
Round Hill 1
Mianus 1
Perryridge 2
Redwood 1
Brighton 1
Downtown 1
#15. The average balance of all accounts
"""""""""""""""""""""""""""""""""""""""""""
AVG(BALANCE)
614.286

#16. name of branches having at least one account,with average balances of account at each
branch,if that average is above 700
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
BRANCH_NAME AVG(BALANCE)
Brighton 750

#17. Names of branches having largest average balance


""""""""""""""""""""""""""""""""""""""""""""""""""""""""
BRANCH_NAME BALANCE
Brighton 750

#18. The no of customers


"""""""""""""""""""""""""""
COUNT(CUSTOMER_NAME)
11

#19.Find the customers who have a loan in downtown branch


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
CUSTOMER_NAME
Williams
Jones
Jackson

#20.Find the customers who have loan between 1500 and 2500
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
CUSTOMER_NAME
Smith
Hayes
Jackson

#21.Find the customers who live in the city "Rye" and have a loan in the bank
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
CUSTOMER_NAME
Curry
Smith

#22. Find the number of borrower in each branch


""""""""""""""""""""""""""""""""""""""""""""""""""
BRANCH_NAME COUNT(CUSTOMER_NAME)
Round Hill 1
Mianus 1
Perryridge 2
Redwood 1
Downtown 3
#23. Find the Branch name having largest average loan amount
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
BRANCH_NAME AVG(AMOUNT)
Redwood 2000

#24. Find the customer’s name who borrows the maximum amount
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
CUSTOMER_NAME LOAN_NUMBER AMOUNT
Smith L-23 2000

#25.Find the customers name with first letter "G"


""""""""""""""""""""""""""""""""""""""""""""""""""
CUSTOMER_NAME
Glenn
Green

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy