Uploaded by Will Reed

Mod5ReedWilliamSQL

advertisement
Module 5 – SQL Query Assignment
Assignment Purpose: Formulate query expressions using SQL query language
Write the following Queries in SQL , run them, and the post the results (Ques on number 1 is done for you) :
1. Find the rst names, last names, and nickNames of all the pastry_chefs
SELECT P.fName, P.lName, P.nickName
FROM PASTRY_CHEF P;
FNAME
-------------------Sylvia
Steve
Barbara
Larry
Mary
Mike
Aaron
Karen
Sam
LNAME
-------------------Jones
Williams
Miller
Stevens
Thomas
Cook
Smith
Kellogg
Jenkins
NICKNAME
-------------------ChefS
SteveW
BarbieGirl
LS
MaryT
Cookie
AS
Kellogg
Jenks
2. Find the nicknames of pastry chefs who have used the prep_tool ‘Cu ng Sheets’
SQL> SELECT DISTINCT pc.nickName
2 FROM PASTRY_CHEF pc
3 INNER JOIN CREATED_BY cb ON pc.pID = cb.pID
4 INNER JOIN PREP_TOOL pt ON cb.pID = pt.pID
5 WHERE pt.Model = 'Cutting Sheets’;
NICKNAME
-------------------SteveW
MaryT
3. Find all the names of the desserts BarbieGirl created
SQL> SELECT d.dName
2 FROM PASTRY_CHEF pc
3 JOIN CREATED_BY cb ON pc.pID = cb.pID
4 JOIN DESSERT d ON cb.dID = d.dID
5 WHERE pc.nickName = ‘BarbieGirl';
DNAME
-----------------------------Red Velvet
4. Find the last names and nickName of Pastry_chefs who have created at least one dessert
SQL> SELECT pc.lName, pc.nickName
2 FROM PASTRY_CHEF pc
3 JOIN CREATED_BY cb ON pc.pID = cb.pID
4 GROUP BY pc.lName, pc.nickName
5 HAVING COUNT(cb.dID) >= 1;
ti
NICKNAME
tti
fi
LNAME
-------------------- -------------------Stevens
LS
Williams
SteveW
Thomas
MaryT
Cook
Cookie
Jones
ChefS
Miller
BarbieGirl
Jenkins
Jenks
5. Find the nickNames any Pastry_chefs who have created at least one dessert, but did not make category pie
SQL> SELECT DISTINCT pc.nickName
2 FROM PASTRY_CHEF pc
3 INNER JOIN CREATED_BY cb ON pc.pID = cb.pID
4 INNER JOIN DESSERT d ON cb.dID = d.dID
5 WHERE d.category <> ‘pie';
NICKNAME
-------------------LS
BarbieGirl
MaryT
SteveW
Cookie
Jenks
6. Find the last names of any Pastry_chefs who have created at least one dessert, but did not make ‘red velvet’
SQL> SELECT DISTINCT pc.lName
2 FROM PASTRY_CHEF pc
3 JOIN CREATED_BY cb ON pc.pID = cb.pID
4 JOIN DESSERT d ON cb.dID = d.dID
5 WHERE d.dName <> 'red velvet’;
LNAME
-------------------Cook
Thomas
Miller
Jenkins
Stevens
Jones
Williams
tti
tti
7. Find the nickNames of Pastry_chefs who do not use ‘Cu ng Sheets’ as Prep tools
SQL> SELECT DISTINCT pc.nickName
2 FROM PASTRY_CHEF pc
3 WHERE pc.pID NOT IN (
4 SELECT pID
5 FROM PREP_TOOL
6 WHERE Model = 'Cu ng Sheets'
7 );
NICKNAME
------------------AS
LS
ChefS
BarbieGirl
Kellogg
Jenks
Cookie
8. Find the rst names of Pastry_chefs who have created both 'Cookies' and ‘Custard’
SQL> SELECT DISTINCT pc.fName
2 FROM PASTRY_CHEF pc
3 JOIN CREATED_BY cb1 ON pc.pID = cb1.pID
4 JOIN CREATED_BY cb2 ON pc.pID = cb2.pID
5 JOIN DESSERT d1 ON cb1.dID = d1.dID
6 JOIN DESSERT d2 ON cb2.dID = d2.dID
7 WHERE d1.dName = 'Cookies'
8 AND d2.dName = 'Custard';
no rows selected
9. Find the youngest age and the nickName from Pastry_chef table
SQL> SELECT age AS youngest_age, nickName
2 FROM PASTRY_CHEF
3 WHERE age = (SELECT MIN(age) FROM PASTRY_CHEF);
YOUNGEST_AGE NICKNAME
——————— -------------------21
AS
10. Find all the secretIngredients used Miami and list the name of the dessert
SQL> SELECT d.dName AS dessert_name, cb.secretIngredient
2 FROM DESSERT d
3 JOIN CREATED_BY cb ON d.dID = cb.dID
4 WHERE cb.loca on = 'Miami';
DESSERT_NAME
SECRETINGREDIENT
------------------------------ -----------------------------Creme Brulee
steeped espresso beans
Sugar
orange jest
Red Velvet
mayonnaise
Donut
Instant mashed Potatoes
11. Find the nickName, dessert name and secretIngredient for any pastry chefs younger than 33
SQL> SELECT pc.nickName, d.dName AS dessert_name, cb.secretIngredient
2 FROM PASTRY_CHEF pc
3 JOIN CREATED_BY cb ON pc.pID = cb.pID
4 JOIN DESSERT d ON cb.dID = d.dID
5 WHERE pc.age < 33;
ti
fi
NICKNAME
DESSERT_NAME
SECRETINGREDIENT
-------------------- ------------------------------ -----------------------------ChefS
Banana Cream
citrus juice
MaryT
MaryT
SteveW
BarbieGirl
ChefS
Jenks
Creme Brulee
Chocolate Chip
Sugar
Red Velvet
Apple
Donut
steeped espresso beans
vanilla and lemon
orange jest
mayonnaise
apple cider vinegar
Instant mashed Potatoes
12. Find the secret Ingredient and dessert name of any desserts that begin with ‘C’
SQL> SELECT d.dName AS dessert_name, cb.secretIngredient
2 FROM DESSERT d
3 JOIN CREATED_BY cb ON d.dID = cb.dID
4 WHERE d.dName LIKE 'C%';
DESSERT_NAME
SECRETINGREDIENT
------------------------------ -----------------------------Creme Brulee
salt
Chocolate Chip
vanilla and lemon
Creme Brulee
steeped espresso beans
Chocolate layer
beets
13. Write your own query request
Find the nickNames of pastry chefs who have used the prep tool brand ‘Pyrex’
14. Write your solu on to the query from ques on 13.
SQL> SELECT DISTINCT pc.nickName
2 FROM PASTRY_CHEF pc
3 JOIN PREP_TOOL pt ON pc.pID = pt.pID
4 WHERE pt.Brand = 'Pyrex';
NICKNAME
-------------------ChefS
ti
ti
MaryT
Download