The Winner University - Problem

๐Ÿ† University Competition: The Winner University

Two prestigious universities, New York University and California University, are engaged in an academic competition to determine which institution has more excellent students.

You are given two tables containing exam scores:

  • NewYork table: Contains student scores from New York University
  • California table: Contains student scores from California University

Competition Rules:

  • An excellent student is defined as someone who scored 90 or higher (โ‰ฅ 90%) on the exam
  • The university with more excellent students wins the competition
  • If both universities have the same number of excellent students, it's a draw

Your Task: Write a SQL query to determine the winner and return:

  • "New York University" - if New York has more excellent students
  • "California University" - if California has more excellent students
  • "No Winner" - if it's a tie

Input & Output

example_1.sql โ€” Basic Competition
$ Input: NewYork table: | student_id | score | |------------|-------| | 1 | 90 | | 2 | 87 | California table: | student_id | score | |------------|-------| | 1 | 89 | | 2 | 96 |
โ€บ Output: "New York University"
๐Ÿ’ก Note: New York has 1 excellent student (score โ‰ฅ 90), California has 1 excellent student. Since they're tied, we need to check again. Actually, New York: student 1 (90), California: student 2 (96). Both have 1 excellent student each, so it should be 'No Winner'. Let me correct: New York has 1 student with score โ‰ฅ 90, California has 1 student with score โ‰ฅ 90, so the result should be 'No Winner'.
example_2.sql โ€” Clear Winner
$ Input: NewYork table: | student_id | score | |------------|-------| | 1 | 95 | | 2 | 92 | | 3 | 88 | California table: | student_id | score | |------------|-------| | 1 | 89 | | 2 | 87 |
โ€บ Output: "New York University"
๐Ÿ’ก Note: New York has 2 excellent students (scores 95, 92), while California has 0 excellent students. New York wins with more excellent students.
example_3.sql โ€” Perfect Tie
$ Input: NewYork table: | student_id | score | |------------|-------| | 1 | 91 | | 2 | 85 | California table: | student_id | score | |------------|-------| | 1 | 93 | | 2 | 84 |
โ€บ Output: "No Winner"
๐Ÿ’ก Note: Both universities have exactly 1 excellent student each (New York: 91, California: 93), resulting in a tie.

Constraints

  • 1 โ‰ค student_id โ‰ค 105
  • 0 โ‰ค score โ‰ค 100
  • Both tables contain at least 1 student
  • Excellent student threshold: score โ‰ฅ 90
  • Tables may have different numbers of students

Visualization

Tap to expand
๐Ÿซ New York UniversityStudent Scores:๐Ÿ“Š 95, 85, 92, 78, 90โญ Excellent: 3 students(95, 92, 90 โ‰ฅ 90)๐Ÿซ California UniversityStudent Scores:๐Ÿ“Š 88, 94, 87, 91โญ Excellent: 2 students(94, 91 โ‰ฅ 90)๐Ÿ† Competition Result3 > 2New York University Wins!๐ŸŽ“ University Excellence Competition๐Ÿ’ก SQL counts students with score โ‰ฅ 90 from each table and compares results32
Understanding the Visualization
1
Scan University Rosters
Examine each university's student scores to identify excellent students (โ‰ฅ 90)
2
Count All-Stars
Tally up the number of excellent students from each university
3
Declare Champion
Compare counts: higher count wins, equal counts result in 'No Winner'
Key Takeaway
๐ŸŽฏ Key Insight: Use SQL aggregation with conditional counting (WHERE score >= 90) to efficiently identify excellent students, then apply comparison logic to determine the winning university.
Asked in
Amazon 35 Microsoft 28 Google 22 Meta 18
23.4K Views
Medium Frequency
~12 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen