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...
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 —in particular, no outer joins or aggregations). Type your answers. If you can’t find Greek letters in your word processor, you can simply write out the operator, all uppercase (i.e. ’SELECT’). Please use renaming consistently, as indicated in the handout. Before starting, make sure you understand the schema of the database. If you...
Given the following relational schema, write queries in SQL to answer the English questions. There is...
Given the following relational schema, write queries in SQL to answer the English questions. There is a shipment database on the MySQL server. You can also use the DDL for MySQL. You must only submit the SQL for your answers but you can include the query output as well to help the TA with marking. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid: integer, shipdate: Date/Time) ShippedProduct(sid:...
Given the following relational schema, write queries in SQL to answer the English questions. There is...
Given the following relational schema, write queries in SQL to answer the English questions. There is a shipment database on the MySQL server. You can also use the DDL for MySQL. You must only submit the SQL for your answers but you can include the query output as well to help the TA with marking. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid: integer, shipdate: Date/Time) ShippedProduct(sid:...
This is t a relational database please write SQL queries to solve the listed questions. The...
This is t a relational database please write SQL queries to solve the listed questions. The database is a variation of the “Movie Database” . There are several differences in it, so look it over carefully before writing your SQL queries Notes: TheaterNum, MovieNum, and ActorNum are numeric primary key fields in their respective tables. Movie and actor names are not assumed to be unique unless specified otherwise in a question. In the THEATER table, Capacity is the number of...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT