0% found this document useful (0 votes)
73 views3 pages

Case Study

The document contains sample SQL queries and questions about two tables: a Repayment table with borrower loan repayment data and a Movie table with information about movies. The questions test various SQL skills like selecting data that meets certain criteria, aggregating data using functions like SUM, sorting results, joining tables, and counting/filtering records. The questions would need to be answered by writing the appropriate SQL queries to retrieve the requested data.

Uploaded by

Noona Free
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)
73 views3 pages

Case Study

The document contains sample SQL queries and questions about two tables: a Repayment table with borrower loan repayment data and a Movie table with information about movies. The questions test various SQL skills like selecting data that meets certain criteria, aggregating data using functions like SUM, sorting results, joining tables, and counting/filtering records. The questions would need to be answered by writing the appropriate SQL queries to retrieve the requested data.

Uploaded by

Noona Free
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/ 3

FINAL EXAMINATION

CS202 (SQL)
Part I. Answer What is being Asked (10 points)

Table Repayment:

(borrower_id,name,address,loanamount,requestdate,repayment_date,repayment_amount)

CREATE DATABASE DataBaseLoan


CREATE TABLE TableLoan(
Borrower_ID int,
Name varchar(255),
Address varchar(255),
LoanAmount int,
Request_Date varchar(255),
Repayment_Date varchar(255),
Repayment_Amount int
)

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.

SELECT address, SUM(Repayment_Amount)


FROM Repayment
GROUP BY 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.

DELETE FROM Repayment A


WHERE LoanAmount=
(SELECT SUM(Repayment_Amount)
FROM Repayment B
WHERE B.Borrower_ID=A.Borrower_ID AND B.Request_Date=A.Request_Date);
Question #5: Write an SQL command which DISPLAY loan amount if the is less than five years in
advanced the payment.

Part II. Write an SQL Command: (20 pts) Table Movie

Number Name Type Rating Stars Qty Price


1 probinsyano action PG13 coco 4 49.95
2 General’s acrion PG13 angel 5 59.95
daughter
3 Firt yaya drama pg gabby 4 49.95
4 Dalawang drama PG13 ken 3 39.95
ikaw
5 Bubble gum comedy G michael 5 59.95
6 NCAA Sport G LPU 3 39.95

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

1. Find the total value of the movie available in the tv


SELECT SUM(Price)
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;

3. Display all movies sorted by QTY in decreasing order


SELECT Name, Qty
FROM TABLE
ORDER BY Qty DESC;
4. Display Report listing a movie number, and current value for all movie as QTY*Price*1.15 in the above
table

SELECT Number,
Qty * Price As Total_Price
FROM TABLE

5. Count the number o movies Where Rating is not “G”

SELECT * FROM TABLE WHERE Rating NOT LIKE 'G';


SELECT SUM(Qty)
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)

SELECT * FROM TABLE WHERE Rating = 'PG13'

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)

You might also like