
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
thumb_up100%

Transcribed Image Text:### SQL Exercise Example: Counting Eye Colors in Monsters Table
#### Objective:
To determine the SQL command needed to count values in the attribute "EYE_COLOR" and place this count in a derived column named "EYE_COLOR_MONSTER_TOTAL" from the table "MONSTERS", specifically for monsters whose "EVIL_POWER" is "Glamouring". The results should list the different eye colors and the number of monsters for each color, but only display colors if the count of monsters with that eye color is greater than 5.
#### Instructions:
Drag the appropriate SQL keywords and phrases to the provided blanks to complete the SQL statement.
#### SQL Statement Construction:
1. **SELECT** - The keyword used to specify that columns should be returned from the database.
2. **EYE_COLOR** - The attribute that we want to count values for.
3. **COUNT(EYE_COLOR)** - The function to count occurrences of each eye color.
4. **AS EYE_COLOR_MONSTER_TOTAL** - Assigning a name to our derived column that holds the count.
5. **FROM MONSTERS** - Indicates the table we are querying data from.
6. **WHERE EVIL_POWER = 'Glamouring'** - Filtering the rows to include only those monsters whose "EVIL_POWER" is "Glamouring".
7. **GROUP BY EYE_COLOR** - Grouping the results based on "EYE_COLOR".
8. **HAVING COUNT(EYE_COLOR) > 5** - Filtering the grouped results to only include those groups where the count is greater than 5.
9. **ORDER BY SKIN_COLOR DESC** - Optional ordering of the results based on another attribute, such as "SKIN_COLOR".
#### Complete SQL Statement:
```sql
SELECT
EYE_COLOR,
COUNT(EYE_COLOR) AS EYE_COLOR_MONSTER_TOTAL
FROM
MONSTERS
WHERE
EVIL_POWER = 'Glamouring'
GROUP BY
EYE_COLOR
HAVING
COUNT(EYE_COLOR) > 5
ORDER BY
SKIN_COLOR DESC;
```
This SQL query effectively retrieves the count of monsters with each eye color that have "Glamouring" as their "EVIL_POWER", but only for those eye colors that appear more than 5 times. The results are further ordered by the "SKIN_COLOR" attribute in descending order for additional sorting.
##### Drop-down Options Provided:
-
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 1. How to delete an existing table "t_person" in SQL? 2. How to use SQL to add a field "p_address" to a table "t_person"?arrow_forwardI want to write the SQL to create the tables for the ERD attached, but I also want to add this to the tables: rental date, due date, and return date so that I can support overdue queries. I also want it so each table has primary keys and foreign keys. I want it so the tables have at least 4 rows of data. How can I do this? Thank you for your help as I learn more about SQL and table creation.arrow_forwardPLZ HELP WITH THE FOLLOWING QUESTION Using oralce sql or sql live Create a view named all_volunteer that gets details of all volunteers that assigned tasks in the organization. CREATE TABLE Packinglist( List_ID INT NOT NULL, Name VARCHAR(50), Description VARCHAR(100), PRIMARY KEY(List_ID)); CREATE TABLE Task( Task_Code INT NOT NULL, List_ID INT, Task_Description VARCHAR(100), Type VARCHAR(30), Status VARCHAR(20), PRIMARY KEY(Task_Code), FOREIGN KEY(List_ID) REFERENCES Packinglist(List_ID)); CREATE TABLE Volunteer( Vol_ID INT NOT NULL, Name VARCHAR(50), Telephone NUMBER, Address VARCHAR(100), PRIMARY KEY(Vol_ID)); CREATE TABLE Assignment( Vol_ID INT, Task_Code INT, Start_Time TIME, End_Time TIME, PRIMARY KEY(Vol_ID, Task_Code), FOREIGN KEY(Vol_ID) REFERENCES Volunteer(Vol_ID), FOREIGN KEY(Task_Code) REFERENCES Task(Task_Code)); CREATE TABLE Package( Pack_ID INT NOT NULL, Task_Code INT, Date DATE, Weight FLOAT, PRIMARY…arrow_forward
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education