Case Study
Case Study
CS202 (SQL)
Part I. Answer What is being Asked (10 points)
Table Repayment:
(borrower_id,name,address,loanamount,requestdate,repayment_date,repayment_amount)
Question #1: Write an SQL request that returns all the tuples with information on repayments from the
borrower with id equal to 42, and where the loan amount exceeds 1000 USD.
SELECT *
FROM Repayment
WHERE Borrower_ID=42 AND LoanAmount>1000;
Question #2: Write an SQL request that for each address finds the total repaid amount for the address.
Question #3: Write an SQL request that finds all names which has a unique address, which to say is
where there does not exist a tuple with a different name and same address.
SELECT name
FROM Repayment A
WHERE 1=
(SELECT COUNT(DISTINCT name)
FROM Repayment B
WHERE A.address=B.address);
Question #4: Write an SQL command, which deletes all information on ended loans which is to say loans
where the total repaid amount equals the lend amount.
Questions:
CREATE DATABASE FINAL
CREATE TABLE TABLE(
Number int,
Name varchar(255),
Type varchar(255),
Rating varchar(255),
Stars varchar(255),
Qty int,
Price float
)
INSERT INTO TABLE VALUES ('1','Probinsyano','Action','PG13','Coco','4','49.95')
INSERT INTO TABLE VALUES ('2','Gernerals Daugther','Acrion','PG13','Angel','5','59.95')
INSERT INTO TABLE VALUES ('3','Firt Yaya','Drama','PG','Gabby','4','49.95')
INSERT INTO TABLE VALUES ('4','Dalawang Ikaw','Drama','PG13','Ken','3','39.95')
INSERT INTO TABLE VALUES ('5','Bubble Gum','Comedy','G','Michael','5','59.95')
INSERT INTO TABLE VALUES ('6','NCAA','Sport','G','LPU','3','39.95')
SELECT * FROM TABLE
2. Display a list of all movies with price over 20 and sorted by price
SELECT Name, Price
FROM TABLE
ORDER BY Price ASC;
SELECT Number,
Qty * Price As Total_Price
FROM TABLE
6. Write an SQL query to find movies who earn the top three price and loan in each of the table
movie and repayment. (4 pts)
7. Write an SQL query to report how many ratings is equal to PG13 in Table movie.
8. Find the total value of the loan amount less than USD100,000 in Table repayment. And
calculate the total value of PG13 in table movie. (4 pts)