Question

In: Computer Science

Write the following questions as queries in SQL. Use only the operators discussed in class (no...

Write the following questions as queries in SQL. Use only the operators discussed in class (no outer joins)

Consider the following database schema:

INGREDIENT(ingredient-id,name,price-ounce)

RECIPE(recipe-id,name,country,time)

USES(rid,iid,quantity)

where INGREDIENT lists ingredient information (id, name, and the price per ounce); RECIPE lists recipe information (id, name, country of origin, and time it takes to cook it); and USES tells us which ingredients (and how much of each) a recipe uses. The primary key of each table is underlined; rid is a foreign key to RECIPE and iid is a foreign key to INGREDIENT

Write the following queries in SQL.

1. Find the names of French recipes that use butter and take longer than 45 minutes to cook.

2. Find the names of recipes that use butter or lard.

3. Find the names of recipes that use butter and lard.

4. Find the name of recipes that do not use any butter.

5. Find the names of recipes that use 2 or more ingredients.

6. Fing the names of ingredients that are used in a single recipe (ie. in one recipe only).

7. The cost of an ingredient in a recipe is the price per ounce of the ingredient times the quantity of ingredient used in the recipe. The cost of a recipe is the sum of the cost of its ingredients. Calculate the cost for all recipes.

8. Find the recipe(s) with the largest number of ingredients (NOTE: there can be more than one).

9. Find the number of recipes on each country that use flour.

10. Find the number of recipes per country, but show only countries with at least 5 recipes.

11. (*) Find the names of recipes where at least 3 oz. (quantity) of every ingredient are used.

NOTE: this means that, however many ingredients are used in a recipe, at least 3 oz. of each ingredient is used.

Solutions

Expert Solution

1) SELECT RECIPE.name FROM RECIPE

INNER JOIN USES ON RECIPE.recipe-id = USES.rid

WHERE RECIPE.country='French' and RECIPE.time > 45 and RECIPE.recipe-id IN (SELECT USES.rid FROM USES inner join INGREDIENT on USES.iid=INGREDIENT.ingredient-id WHERE INGREDIENT.name='butter');

2)SELECT RECIPE.name FROM RECIPE

INNER JOIN USES ON RECIPE.recipe-id = USES.rid

WHERE RECIPE.recipe-id IN (SELECT USES.rid FROM USES inner join INGREDIENT on USES.iid=INGREDIENT.ingredient-id WHERE INGREDIENT.name='butter' or INGREDIENT.name='lard');

3)SELECT RECIPE.name FROM RECIPE

INNER JOIN USES ON RECIPE.recipe-id = USES.rid

WHERE RECIPE.recipe-id IN (SELECT USES.rid FROM USES inner join INGREDIENT on USES.iid=INGREDIENT.ingredient-id WHERE INGREDIENT.name='butter' and INGREDIENT.name='lard');

4)SELECT RECIPE.name FROM RECIPE

INNER JOIN USES ON RECIPE.recipe-id = USES.rid

WHERE RECIPE.recipe-id IN (SELECT USES.rid FROM USES inner join INGREDIENT on USES.iid=INGREDIENT.ingredient-id WHERE INGREDIENT.name<>'butter' );


Related Solutions

Write the following questions as queries in SQL. Use only the operators discussed in class (no...
Write the following questions as queries in SQL. Use only the operators discussed in class (no outer joins) Consider the following database schema: INGREDIENT(ingredient-id,name,price-ounce) RECIPE(recipe-id,name,country,time) USES(rid,iid,quantity) where INGREDIENT lists ingredient information (id, name, and the price per ounce); RECIPE lists recipe information (id, name, country of origin, and time it takes to cook it); and USES tells us which ingredients (and how much of each) a recipe uses. The primary key of each table is underlined; rid is a foreign...
Write the following questions as queries in RELATIONAL ALGEBRA. Use only the operators discussed in class...
Write the following questions as queries in RELATIONAL ALGEBRA. Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference and renaming). The following database schema is given: ATHLETE(name,age,height,weight,country) RACE(id,location,date,time-start,distance) COMPETES(aname,rid,time,position) where ATHLETE has information about runners (their name, age, height, weight, and nationality); RACE has information about races (id, location, date when it’s held, time it starts, and distance ran); and COMPETES keeps track of which runners run on with race, the time it...
Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference...
Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference and renaming). Type your answers. The following database schema is given: ATHLETE(name,age,height,weight,country) RACE(id,location,date,time-start,distance) COMPETES(aname,rid,time,position) where ATHLETE has information about runners (their name, age, height, weight, and nationality); RACE has information about races (id, location, date when it’s held, time it starts, and distance ran); and COMPETES keeps track of which runners run on with race, the time it took them to complete the race,...
Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference...
Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference and renaming). Type your answers. Consider the following database schema: INGREDIENT(ingredient-id,name,price-ounce) RECIPE(recipe-id,name,country,time) USES(rid,iid,quantity) where INGREDIENT lists ingredient information (id, name, and the price per ounce); RECIPE lists recipe information (id, name, country of origin, and time it takes to cook it); and USES tells us which ingredients (and how much of each) a recipe uses. The primary key of each table is underlined; rid...
Write the following SQL queries and show the corresponding output of the DBMS: 1) Write an...
Write the following SQL queries and show the corresponding output of the DBMS: 1) Write an SQL statement to display all the information of all Nobel Laureate winners. 2) Write an SQL statement to display the string "Hello, World!". 3) Write an SQL query to display the result of the following expression: 2 * 14 +76. 4) Write an SQL statement to display the winner and category of all Laureate winners. 5) Write an SQL query to find the winner(s)...
In this assignment, you are required to write the SQL statements to answer the following queries...
In this assignment, you are required to write the SQL statements to answer the following queries using PostgreSQL system. The SQL statements comprising the DDL for Henry Books Database are given to you in two files. For that database, answer the following queries. Create the files Q1 to Q10 in PostgreSQL. Do follow the restrictions stated for individual queries. 1. List the title of each book published by Penguin USA. You are allowed to use only 1 table in any...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a select statement to show the invoicelineitemdescriptions that have the total invoicelineitemamount >1000 and the number of accountno is >2. 10. Write a select statement that returns the vendorid, paymentsum of each vendor, and the number of invoices of each vendor, where paymentsum is the sum of the paymentotal column. Return only the top ten vendors who have been paid the most and the number...
Basic SQL Use the following schema to answer the queries below using SQL DEVICE [dno, dtype,...
Basic SQL Use the following schema to answer the queries below using SQL DEVICE [dno, dtype, price] PROVIDER [pno, pname, web] SERVICE [dno, pno, servicedate] SERVICE.dno references DEVICE.dno SERVICE.pno references PROVIDER.pno bold is underline. a) Find the dno for the most expensive device b) Find all providers that have the work fast in the name c) Find the number of different device types (dtype) d) Give all details of devices with price more than $400
Write SQL queries below for each of the following: List the names and cities of all...
Write SQL queries below for each of the following: List the names and cities of all customers List the different states the vendors come from (unique values only, no duplicates) Find the number of customers in California List product names and category descriptions for all products supplied by vendor Proformance List names of all employees who have sold to customer Rachel Patterson
Please use the books database pasted under question 4 to design the following SQL queries. Use...
Please use the books database pasted under question 4 to design the following SQL queries. Use any method such as subqueries, equi-join/inner-join, outer join, EXISTS 1. Find the name(s) of the publisher(s) who have published the computer book. 2. Find the name(s) of the author(s) that have authored more than one books. 3. Find the name(s) of the publisher(s) who published the least expensive book. 4. Find the name(s) of the author(s) who wrote the book with the greatest number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT