Uploaded by Will Reed

Mod5skeleton

advertisement
SQL> Select * from PASTRY_CHEF;
• SQL> Select * from DESSERT;
• SQL> Select * from CREATED_BY;
• SQL> Select * from PREP_TOOL;
CREATE TABLE PASTRY_CHEF (
pID NUMBER,
fName VARCHAR(20),
lName VARCHAR(20),
nickName VARCHAR(20),
age NUMBER
);
1. Find the first names, last names, and nickNames of all the pastry_chefs
SELECT P.fName, P.lName, P.nickName
FROM PASTRY_CHEF P;
2. Find the nicknames of pastry chefs who have used the prep_tool ‘Cutting Sheets
SELECT DISTINCT pc.nickName
FROM PASTRY_CHEF pc
INNER JOIN CREATED_BY cb ON pc.pID = cb.pID
INNER JOIN PREP_TOOL pt ON cb.pID = pt.pID
WHERE pt.Model = 'Cutting Sheets';
3. Find all the names of the desserts BarbieGirl created
SELECT d.dName
FROM PASTRY_CHEF pc
JOIN CREATED_BY cb ON pc.pID = cb.pID
JOIN DESSERT d ON cb.dID = d.dID
WHERE pc.nickName = 'BarbieGirl';
4. Find the last names and nickName of Pastry_chefs who have created at least one dessert
SELECT pc.lName, pc.nickName
FROM PASTRY_CHEF pc
JOIN CREATED_BY cb ON pc.pID = cb.pID
GROUP BY pc.lName, pc.nickName
HAVING COUNT(cb.dID) >= 1;
5. Find the nickNames any Pastry_chefs who have created at least one dessert, but did not make category pie
SELECT DISTINCT pc.nickName
FROM PASTRY_CHEF pc
INNER JOIN CREATED_BY cb ON pc.pID = cb.pID
INNER JOIN DESSERT d ON cb.dID = d.dID
WHERE d.category <> 'pie';
6. Find the last names of any Pastry_chefs who have created at least one dessert, but did not make ‘red velvet’
SELECT DISTINCT pc.lName
FROM PASTRY_CHEF pc
JOIN CREATED_BY cb ON pc.pID = cb.pID
JOIN DESSERT d ON cb.dID = d.dID
WHERE d.dName <> 'red velvet';
7. Find the nickNames of Pastry_chefs who do not use ‘Cutting Sheets’ as Prep tools
SELECT DISTINCT pc.nickName
FROM PASTRY_CHEF pc
WHERE pc.pID NOT IN (
SELECT pID
FROM PREP_TOOL
WHERE Model = 'Cutting Sheets'
);
8. Find the first names of Pastry_chefs who have created both 'Cookies' and 'Custard'
SELECT DISTINCT pc.fName
FROM PASTRY_CHEF pc
JOIN CREATED_BY cb1 ON pc.pID = cb1.pID
JOIN CREATED_BY cb2 ON pc.pID = cb2.pID
JOIN DESSERT d1 ON cb1.dID = d1.dID
JOIN DESSERT d2 ON cb2.dID = d2.dID
WHERE d1.dName = 'Cookies'
AND d2.dName = 'Custard';
9. Find the youngest age and the nickName from Pastry_chef table
SELECT age AS youngest_age, nickName
FROM PASTRY_CHEF
WHERE age = (SELECT MIN(age) FROM PASTRY_CHEF);
10. Find all the secretIngredients used Miami and list the name of the dessert
SELECT d.dName AS dessert_name, cb.secretIngredient
FROM DESSERT d
JOIN CREATED_BY cb ON d.dID = cb.dID
WHERE cb.location = 'Miami';
11. Find the nickName, dessert name and secretIngredient for any pastry chefs younger than 33
SELECT pc.nickName, d.dName AS dessert_name, cb.secretIngredient
FROM PASTRY_CHEF pc
JOIN CREATED_BY cb ON pc.pID = cb.pID
JOIN DESSERT d ON cb.dID = d.dID
WHERE pc.age < 33;
12. Find the secret Ingredient and dessert name of any desserts that begin with 'C'
SELECT d.dName AS dessert_name, cb.secretIngredient
FROM DESSERT d
JOIN CREATED_BY cb ON d.dID = cb.dID
WHERE d.dName LIKE 'C%';
13 (custom query). Find the nicknames of pastry chefs who have used the prep_tool BRAND 'Pyrex’
SELECT DISTINCT pc.nickName
FROM PASTRY_CHEF pcS
JOIN PREP_TOOL pt ON pc.pID = pt.pID
WHERE pt.Brand = 'Pyrex';
Download