Question

In: Computer Science

USING THE FOLLOWING DATABASE: [Please read the instructions thoroughly, this is my 6th time posting this...

USING THE FOLLOWING DATABASE: [Please read the instructions thoroughly, this is my 6th time posting this same question.]

=========

-- SQL Script for Generating Kitchen Database

drop database if exists kitchen;
create database kitchen;
use kitchen;
drop table if exists recipe;

drop table if exists food;
create table food
(fid int,
fname varchar(45) not null unique,
primary key(fid));

drop table if exists ingredient;
create table ingredient
(iid int,
iname varchar(45) not null unique,
caloriepergram float,
category varchar(20),
primary key(iid)
);

create table recipe (
fid int,
iid int,
amount int not null,
primary key(fid,iid),
foreign key(fid) references food(fid),
foreign key(iid) references ingredient(iid)
);

INSERT INTO `food` VALUES (1,'Fried Rice'),(2,'Orange Chicken'),(3,'BBQ Pork'),(4,'BBQ Chicken'),(5,'Fried Noodle'),(6,'Mongolian Beef');

INSERT INTO `ingredient` VALUES(21,'Pork', 1.44, 'Meat'),(23,'Chicken', 1.65, 'Meat'),(24,'Orange', 0.47, 'Vegetable'),(28,'Green Onion', 0.10, 'Vegetable'),(29,'Egg Noodle', 2.0, 'Carbohydrate'),(31,'Beef', 1.8, 'Meat'),(32,'Cilantro',0.10,'Vegetable'),(33,'Carrot', 0.10, 'Vegetable'),(34,'Green Pepper', 1.00, 'Vegetable');

INSERT INTO `recipe` VALUES (1, 21, 10), (2,23,60),(2,24,30),(3,21,60),(4,23,6),(5,23,200),(5,28,60),(5,29,6),(6,28,5),(6,31,60),(1,32,3),(1,33,3),(4,32,1),(6,32,3);

=========

DO THE FOLLOWING:

e) (7 points) List values of fid, fname, iid, iname, and calories of each ingredient for all food items that have chicken as one of the ingredients. Do not include food items that do not have chicken as one of the ingredients. The calories of each ingredient are calculated as the amount of the ingredient (in grams) multiplied with the calories per gram for that ingredient. Return the list in ascending order of fid. Show total calories as a floating point number with two decimal places.
Hint: Join of all three tables. Use the cast() function to show the calorie value as a floating point number with two decimal places.
The correct output has 7 rows!!!!!!!!!!!!

Once again. You need to list ALL INGREDIENTS OF EACH ITEM that has chicken in it. NOT JUST THE ITEM ITS SELF.

Solutions

Expert Solution

Below is the query to find ingredient chicken in recipe

SELECT r.* FROM ingredient i INNER JOIN recipe r ON i.iid = r.iid WHERE iname = "chicken"

Result will look like below.

Below is the query to find fid and fname that have chicken as one of the ingredients.

SELECT f.* FROM food f INNER JOIN recipe r ON f.fid = r.fid WHERE f.fid IN
(SELECT r.fid FROM ingredient i INNER JOIN recipe r ON i.iid = r.iid WHERE iname = "chicken")

Result will look like below.

To display iid and iname perform join with ingredient table.Query is below:

SELECT f.*,i1.iid,i1.iname FROM food f INNER JOIN recipe r ON f.fid = r.fid INNER JOIN ingredient i1
ON i1.iid = r.iid WHERE f.fid IN
(SELECT r.fid FROM ingredient i INNER JOIN recipe r ON i.iid = r.iid WHERE iname = "chicken")

Result will look like below.

Now to display calories as multiplication of caloriepergram and amount of the ingredient and calorie value as floating point number with two decimal places and return the list in ascending order of fid use below query:


SELECT f.*,i1.iid,i1.iname,CAST(r.amount*i1.caloriepergram AS DECIMAL(10,2)) AS calories
FROM food f INNER JOIN recipe r ON f.fid = r.fid INNER JOIN ingredient i1 ON i1.iid = r.iid WHERE f.fid IN
(SELECT r.fid FROM ingredient i INNER JOIN recipe r ON i.iid = r.iid WHERE iname = "chicken") ORDER BY fid ASC

Result will look like below.


Related Solutions

****user comments: PLEASE READ INSTRUCTIONS THOROUGHLY AND KEEP THE STRUCTURE OF THE PROGRAM. JUST ADD THE...
****user comments: PLEASE READ INSTRUCTIONS THOROUGHLY AND KEEP THE STRUCTURE OF THE PROGRAM. JUST ADD THE ADDITIVES NEEDED IN ORDER TO SUFFICE THE PROGRAM. PLEASE MAKE SURE IT IS IN C++ AND WORKS! THANK YOU!**** Write a program that uses a structure to store the following information for a particular month at the local airport: Total number of planes that landed Total number of planes that departed Greatest number of planes that landed in a given day that month Least...
INSTRUCTIONS Read the following case study about Amazon, and then submit a posting with answers to...
INSTRUCTIONS Read the following case study about Amazon, and then submit a posting with answers to the 5 questions below. Your answers will be graded primarily on content, but grammar, spelling, syntax, etc will also count. Please make sure that your answers are labeled to match the Question numbers so that I can easily read (and grade) your submissions CASE STUDY: THE AMAZON OF INNOVATION On December 2, 2013, Amazon.com customers ordered 36.8 million items worldwide, an average of 426...
INSTRUCTIONS Read the following case study about Amazon, and then submit a posting with answers to...
INSTRUCTIONS Read the following case study about Amazon, and then submit a posting with answers to the 5 questions below. Your answers will be graded primarily on content, but grammar, spelling, syntax, etc will also count. Please make sure that your answers are labeled to match the Question numbers so that I can easily read (and grade) your submissions CASE STUDY: THE AMAZON OF INNOVATION On December 2, 2013, Amazon.com customers ordered 36.8 million items worldwide, an average of 426...
This is my second time posting this question. Can the answer be typed please? Its hard...
This is my second time posting this question. Can the answer be typed please? Its hard to read someones handwritten cursive response. In recent years, many elderly people have purchased Medigap insurance policies to cover a growing Medicare copayment. These policies cover some or all of the medical costs not covered by Medicare. Use economic theory to explain how the growth of these policies is likely to influence the demand for health care by elderly people.
I AM POSTING MY QUESTION 12TH TIME PLEASE PROPER EXPLAIN THE FOLLOWING TERMS WITH EXAMPLES 1)...
I AM POSTING MY QUESTION 12TH TIME PLEASE PROPER EXPLAIN THE FOLLOWING TERMS WITH EXAMPLES 1) INCREMENTAL COST 2) OPPORTUNITY COST 3) SUNK COST 4) RECURRING AND NON-RECURRING COST 5) FIXED , VARIABLE, TOTAL COST 6) AVERAGE AND MARGINAL COST 7) ENGINEERING COST AND COST ESTIMATING PLEASE DEFINE ALL THESE THINGS WITH PROPER EXAMPLES I AM PREPARING FOR MY FINAL WHICH IS TOMMOROW
I am posting this for the third time. PLEASE READ EVERYTHING CAREFULLY AND THEN ANSWER I...
I am posting this for the third time. PLEASE READ EVERYTHING CAREFULLY AND THEN ANSWER I am m designing a questionnaire for the topic: FACTORS INFLUENCING CONSUMER BUYING BEHAVIOR IN PURCHASE OF MILK IN ORGANIZED AND UNORGANIZED SECTOR. the study is basically to study the factors that influence consumer decisions in purchase of milk in organized and unorganized sector of milk. For this i need variables that influence purchase of milk in organized and unorganized sector. \ Note: I need...
I am posting this for the third time. PLEASE READ EVERYTHING CAREFULLY AND THEN ANSWER I...
I am posting this for the third time. PLEASE READ EVERYTHING CAREFULLY AND THEN ANSWER I am m designing a questionnaire for the topic: FACTORS INFLUENCING CONSUMER BUYING BEHAVIOR IN PURCHASE OF MILK IN ORGANIZED AND UNORGANIZED SECTOR. the study is basically to study the factors that influence consumer decisions in purchase of milk in organized and unorganized sector of milk. For this i need variables that influence purchase of milk in organized and unorganized sector. Note: I need just...
The Buyer’s Experience Before starting, please read these instructions thoroughly. Purpose: To recognize common sales strategies...
The Buyer’s Experience Before starting, please read these instructions thoroughly. Purpose: To recognize common sales strategies and their effect on the buyer; and analyzes the salesperson’s tactics using material from class. You will be provided with a list of what you are looking for during the interaction. Your Task: Select a product that you have genuine interest in purchasing sometime in the near future. Find a corporation*, big-box store, or a similar retailer in which you can visit to execute...
This is my 3rd time posting this question, first time was wrong: The Zagat Restaurant Survey...
This is my 3rd time posting this question, first time was wrong: The Zagat Restaurant Survey provides food, decor, and service ratings for some of the top restaurants across the United States. For 18 restaurants located in a certain city, the average price of a dinner, including one drink and tip, was $48.60. You are leaving on a business trip to this city and will eat dinner at three of these restaurants. Your company will reimburse you for a maximum...
Please read the instructions and  find attached for the first wiki . Instructions for students: Read carefully...
Please read the instructions and  find attached for the first wiki . Instructions for students: Read carefully the attached document and then post your comments bearing in mind the following questions: 1- What are the pros and cons of rent controls? 2- Why economists disagree on the usefulness of rent control? 3- Do you believe rent control can help the poor? Edit Wiki Content rent control Rent regulation can take various forms, including rent control (the placing of a cap on...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT