Bird
0
0

Given a table students with columns class, score, write a query to find the highest score in each class.

hard📝 Application Q9 of 15
SQL - GROUP BY and HAVING
Given a table students with columns class, score, write a query to find the highest score in each class.
ASELECT class, score FROM students GROUP BY score;
BSELECT class, MAX(score) FROM students;
CSELECT MAX(class), score FROM students GROUP BY score;
DSELECT class, MAX(score) FROM students GROUP BY class;
Step-by-Step Solution
Solution:
  1. Step 1: Determine grouping column

    We want highest score per class, so group by class.
  2. Step 2: Use MAX to find highest score

    MAX(score) returns the highest score in each group.
  3. Final Answer:

    SELECT class, MAX(score) FROM students GROUP BY class; -> Option D
  4. Quick Check:

    Highest score per class = GROUP BY class with MAX(score) [OK]
Quick Trick: Use MAX() with GROUP BY to find highest per group [OK]
Common Mistakes:
MISTAKES
  • Grouping by score instead of class
  • Selecting columns without aggregation
  • Omitting GROUP BY when using aggregate

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes