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}
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:
- List the foods in the database, alphabetically by food name. Only display the first 45 characters of the name. Add the message "Low Nutrient Count" to those foods that have fewer than 80 nutrients associated with them and add the message "High Nutrient Count" to those foods that have more than 120 nutrients associated with them.
- Retrieve the food ID and food names of foods that start with the same 20 characters. Make sure you do not count the same food twice. i.e. "CEREAL, CAPTAIN CRUNCH" will match itself, but we don't want to count that. Sort the results using the food name and food id.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started