U ANSWERS to Firedup Project QUESTIONS
Total Page:16
File Type:pdf, Size:1020Kb

▶ANSWERS TO FIREDUP PROJECT QUESTIONS
Assume that FiredUp has created a database with the following tables:
CUSTOMER (CustomerSK, Name, Phone, EmailAddress)
STOVE (SerialNumber, Type, Version, DateOfManufacture)
REGISTRATION ( CustomerS K, SerialNumbe r, Date)
STOVE_REPAIR (RepairInvoiceNumber, SerialNumber, Date, Description, Cost, CustomerSK)
Code SQL for the following. Assume that all dates are in the format mmddyyyy.
A. Show all of the data in each of the four FiredUp tables.
SELECT * FROM CUSTOMER;
SELECT * FROM STOVE;
SELECT * FROM REGISTRATION;
SELECT * FROM STOVE_REPAIR;
B. List the Versions of all stoves.
SELECT Version FROM STOVE;
To list each very only once use:
SELECT DISTINCT Version FROM STOVE; C. List the Versions of all stoves of the type ‘Fired Now’.
SELECT Version FROM STOVE WHERE Type = ‘Fired Now’;
D. List the SerialNumber and Date of all registrations in the year 2002.
SELECT SerialNumber, Date FROM REGISTRATION WHERE Date Like ‘%2002’;
E. List the SerialNumber and Date of all registrations in February. Use the underscore (_) wildcard.
SELECT SerialNumber, Date FROM REGISTRATION WHERE Date Like ‘02______;
F. List the SerialNumber and Date of all registrations in February. Use the percent (%) wildcard.
SELECT SerialNumber, Date FROM REGISTRATION WHERE Date Like ‘02%’;
G. List the names and email addresses of all customers who have an email address.
SELECT Name, EmailAddress FROM CUSTOMER WHERE EmailAddress IS NOT NULL;
H. List the names of all customers who do not have an EmailAddress; present the results in descending sorted order of Name.
SELECT Name, EmailAddress FROM CUSTOMER WHERE EmailAddress IS NULL ORDER BY Name;
I. Determine the maximum cost of a stove repair.
SELECT MAX (Cost) FROM STOVE_REPAIR;
J. Determine the average cost of a stove repair.
SELECT AVG (Cost) FROM STOVE_REPAIR;
K. Count all stoves.
SELECT COUNT (*) FROM STOVE;
L. Count all stoves of each type and display the Type and count.
SELECT Type, COUNT (*) FROM STOVE GROUP BY Type;
M. List the name and email addresses of all customers who have had a stove repair that cost more than $50. Use a subquery.
SELECT Name, EmailAddress FROM CUSTOMER WHERE CustomerSK IN (SELECT CustomerSK FROM STOVE_REPAIR WHERE Cost > 50.00);
N. List the names and email addresses of all customers who have registered a stove of the type ‘FiredNow’. Use a subquery.
SELECT Name, EmailAddress FROM CUSTOMER WHERE CustomerSK IN (SELECT CustomerSK FROM REGISTRATION WHERE SerialNumber IN (SELECT SerialNumber FROM STOVE WHERE Type = ‘FiredNow’);
O. List the names and email addresses of all customers who have had a stove repair that cost more than $50. Use join with the JOIN ON syntax. SELECT Name, EmailAddress FROM CUSTOMER JOIN (REGISTRATION JOIN STOVE_REPAIR ON REGISTRATION.SerialNumber = STOVE_REPAIR.Serial_Number) ON CUSTOMER.CustomerSK = REGISTRATION.CustomerSK WHERE STOVE_REPAIR.Cost > 50.00;
P. List the names and email addresses of all customers who have registered a stove of type ‘FiredNow’. Use join with the JOIN ON syntax.
SELECT Name, EmailAddress FROM CUSTOMER JOIN REGISTRATION ON CUSTOMER.CustomerSK = REGISTRATION.CustomerSK WHERE STOVE_REPAIR.Type = ‘FiredNow’;
Q. List the names, email addresses, and registration date of all customer registrations.
SELECT Name, EmailAddress, Date FROM CUSTOMER, REGISTRATION WHERE CUSTOMER.CustomerSK = REGISTRATION.CustomerSK; R. Show the names and email addresses of all customers who have registered a stove, and have had any stove repaired.
SELECT Name, EmailAddress FROM CUSTOMER WHERE CustomerSK IN (SELECT CustomerSK FROM REGISTRATION) AND CustomerSK IN (SELECT CustomerSK FROM STOVE_REPAIR);
S. Show the names and email addresses of all customers who have registered a stove, but who have not had any stove repaired.
SELECT Name, EmailAddress FROM CUSTOMER WHERE CustomerSK IN (SELECT CustomerSK FROM REGISTRATION) AND CustomerSK NOT IN (SELECT CustomerSK FROM STOVE_REPAIR);