Bird
0
0

Given a table Scores with columns StudentID, Test1, and Test2, how do you find the highest score among both tests for each student?

hard📝 Application Q9 of 15
SQL - Aggregate Functions
Given a table Scores with columns StudentID, Test1, and Test2, how do you find the highest score among both tests for each student?
ASELECT StudentID, GREATEST(Test1, Test2) FROM Scores;
BSELECT StudentID, MAX(Test1) FROM Scores;
CSELECT StudentID, MAX(Test1) + MAX(Test2) FROM Scores;
DSELECT StudentID, MAX(Test1, Test2) FROM Scores;
Step-by-Step Solution
Solution:
  1. Step 1: Understand MAX() limitation

    MAX() works on one column or across rows, not multiple columns per row.
  2. Step 2: Use GREATEST() for per-row max across columns

    GREATEST(Test1, Test2) returns the higher score between two columns for each row.
  3. Final Answer:

    SELECT StudentID, GREATEST(Test1, Test2) FROM Scores; -> Option A
  4. Quick Check:

    Use GREATEST() for max across columns [OK]
Quick Trick: Use GREATEST() to compare multiple columns per row [OK]
Common Mistakes:
MISTAKES
  • Using MAX() with multiple columns
  • Adding MAX() values incorrectly
  • Ignoring per-row comparison

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes