The Winner University - Problem

You have two tables representing exam scores from two universities:

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

There is a competition between the two universities. The winner is determined by which university has more excellent students (students who scored 90 or above).

Return:

  • 'New York University' if New York has more excellent students
  • 'California University' if California has more excellent students
  • 'No Winner' if both universities have the same number of excellent students

Table Schema

NewYork
Column Name Type Description
student_id PK int Primary key, unique student identifier
score int Student's exam score
Primary Key: student_id
California
Column Name Type Description
student_id PK int Primary key, unique student identifier
score int Student's exam score
Primary Key: student_id

Input & Output

Example 1 — California Wins
Input Tables:
NewYork
student_id score
1 90
2 80
California
student_id score
1 95
2 92
Output:
winner
California University
💡 Note:

New York has 1 excellent student (score >= 90): student 1 with score 90. California has 2 excellent students: student 1 with score 95 and student 2 with score 92. Since California has more excellent students (2 > 1), California University wins.

Example 2 — Draw
Input Tables:
NewYork
student_id score
1 89
2 91
California
student_id score
1 88
2 95
Output:
winner
No Winner
💡 Note:

New York has 1 excellent student (student 2 with score 91). California also has 1 excellent student (student 2 with score 95). Since both universities have the same number of excellent students (1 = 1), the result is a draw.

Example 3 — New York Wins
Input Tables:
NewYork
student_id score
1 93
2 97
3 88
California
student_id score
1 85
2 90
Output:
winner
New York University
💡 Note:

New York has 2 excellent students: student 1 with score 93 and student 2 with score 97. California has 1 excellent student (student 2 with score 90). Since New York has more excellent students (2 > 1), New York University wins.

Constraints

  • 1 ≤ student_id ≤ 10^5
  • 0 ≤ score ≤ 100
  • Both tables contain at least 1 student
  • Excellent student threshold is score ≥ 90

Visualization

Tap to expand
The Winner University ProblemNewYorkID: 1, Score: 90ID: 2, Score: 80Excellent: 1CaliforniaID: 1, Score: 95ID: 2, Score: 92Excellent: 2CompareCalifornia UniversityWinner (2 > 1)Excellent = Score >= 90
Understanding the Visualization
1
Input
Two university tables with student scores
2
Count
Count students with score >= 90 from each university
3
Compare
Return winner based on excellent student counts
Key Takeaway
🎯 Key Insight: Use conditional aggregation to count and compare groups in a single query
Asked in
Amazon 12 Microsoft 8 Facebook 6
28.5K Views
Medium Frequency
~12 min Avg. Time
890 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