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:
NewYorktable: Contains student scores from New York UniversityCaliforniatable: Contains student scores from California University
Competition Rules:
- An excellent student is defined as someone who scored
90or 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
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.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code