Question: (SQL Query Question) The following image is of a database with the tables listed (foodname, foodgroup, nutrientname and nutrientamount) {Please ignore any other table, just

(SQL Query Question) The following image is of a database with the tables listed (foodname, foodgroup, nutrientname and nutrientamount) {Please ignore any other table, just these 4}

(SQL Query Question) The following image is of a database with the

The table foodname contains a row for each food in the database. Each row has a FoodID, a unique identifier for the food, a FoodGroupID that identifies the group this food belongs to, an English (FoodDescription) and a French name (FoodDescriptionF) for the food.

The group table, foodgroup, contains a FoodGroupID and a name for the group in both English(FoodGroupName)and French (FoodGroupNameF) (e.g. Pork Products).

The nutrient name table, nutrientname, contains rows for each nutrient recorded, for example, fat, protein, and vitamin C. In addition, there is an identifier for each nutrient, NutrientNameID and the Unit that the nutrient is measured in (g, mcg, kCal, etc.).

The final table is the main one, nutrientamount. It links the tables foodname and nutrientname. For each food, there are multiple rows in the nutrientamount table, one for each nutrient. Each entry includes the FoodID, the NutrientNameID and how much of that nutrient is present.

Kindly write the following SQL queries to retrieve data from the above database:

1) How many foods are there for the food group 'Spices and Herbs', listed in the database? Show the food group id, the food group name and the foods count?

(I tried the following query and it did not work:

SELECT t2.FoodGroupID, t2.FoodGroupName,count(t1.*) FROM foodname t1 INNER JOIN foodgroup t2 ON t1.FoodGroupID = t2.FoodGroupID AND FoodGroupID = (SELECT FoodGroupID FROM foodgroup WHERE FoodGroupName = 'Spices and Herbs')

Please write different query than above)

2) List the food group name with the number of foods for all food groups listed in the database containing more than 400 food records. Order the list from most number of foods to least?

YIELD NAME YieldID YieldName YieldName YIELD AMOUNT FoodID YieldID YieldAmount YieldDateOfEntry REFUSE NAME RefuselD RefuseName RefuseName REFUSE AMOUNT FoodID Refusel RefuseAmount RefuseDateOfEntry FOOD GROUP FoodGroupID Food Group Code FoodGroupName FoodGroupNameF MEASURE NAME MeasurelD MeasureName MeasureNameF CONVERSION FACTOR FoodID MeasurelD ConversionFactor Value ConvFactor DateOfEntry FOOD NAME FoodID FoodCode FoodGroupID FoodSourceID FoodDescription FoodDescription CountryCode FoodDateOfEntry FoodDateOfPublication ScientificName FOOD SOURCE FoodSourceID FoodSource Code FoodSource Description FoodSource DescriptionF NUTRIENT NAME NutrientNameID NutrientCode NutrientSymbol Unit NutrientName NutrientNameF Tagname Nutrient Decimals NUTRIENT AMOUNT FoodID NutrientNameld Nutrient SourceID Nutrient Value StandardError NumberOfObservation Nutrient DateOfEntry NUTRIENT SOURCE Nutrient SourcelD Nutrient Source Code NutrientSourceDescription NutrientSource DescriptionF

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!