Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question
100%
### 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:

-
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education