Skip to content

Commit fdf8d9f

Browse files
committed
Upload 188
1 parent 0f7f3ff commit fdf8d9f

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- markdownlint-disable MD041 -->
22
[![eevveerryyddaayy release](https://img.shields.io/badge/eevveerryyddaayy-v1.3.0-blue.svg)](https://github.com/ggeerraarrdd/eevveerryyddaayy/)
3-
[![Solved](https://img.shields.io/badge/solved-187-green.svg)](#index)
3+
[![Solved](https://img.shields.io/badge/solved-188-green.svg)](#index)
44
<!-- markdownlint-enable MD041 -->
55

66
# SQL Everyday
@@ -221,6 +221,7 @@ Because this project necessitated a framework to enable consistent daily practic
221221
| 185 | [Sales Analysis I](https://leetcode.com/problems/sales-analysis-i/description/) | [Solution](solutions/185_sales_analysis_i.md) | LeetCode | Easy | |
222222
| 186 | [Sales Analysis II](https://leetcode.com/problems/sales-analysis-ii/description/) | [Solution](solutions/186_sales_analysis_ii.md) | LeetCode | Easy | `STRING_AGG` vs `GROUP_CONCAT` |
223223
| 187 | [Sales Analysis III](https://leetcode.com/problems/sales-analysis-iii/description/) | [Solution](solutions/187_sales_analysis_iii.md) | LeetCode | Easy | `HAVING` |
224+
| 188 | [The Winner University](https://leetcode.com/problems/the-winner-university/description/) | [Solution](solutions/188_the_winner_university.md) | LeetCode | Easy | |
224225
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
225226
<!--- cSpell:enable --->
226227

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# SQL Everyday \#188
2+
3+
## The Winner University
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Easy
7+
8+
## Problem
9+
10+
There is a competition between New York University and California University. The competition is held between the same number of students from both universities. The university that has more **excellent students** wins the competition. If the two universities have the same number of **excellent students**, the competition ends in a draw.
11+
12+
An **excellent student** is a student that scored `90%` or more in the exam.
13+
14+
Return:
15+
16+
* **"New York University"** if New York University wins the competition.
17+
* **"California University"** if California University wins the competition.
18+
* **"No Winner"** if the competition ends in a draw. [[Full Description](https://leetcode.com/problems/the-winner-university/description/)]
19+
20+
## Submitted Solution
21+
22+
```sql
23+
-- Submitted Solution
24+
WITH cte1 AS (
25+
SELECT
26+
'New York University' AS university
27+
,COUNT(DISTINCT student_id) AS student_count
28+
FROM NewYork
29+
WHERE score >= 90
30+
GROUP BY university
31+
UNION
32+
SELECT
33+
'California University' AS university
34+
,COUNT(DISTINCT student_id) AS student_count
35+
FROM California
36+
WHERE score >= 90
37+
GROUP BY university
38+
),
39+
cte2 AS (
40+
SELECT
41+
*
42+
,1.0 * student_count / SUM(student_count) OVER () AS percentage
43+
FROM cte1
44+
)
45+
SELECT
46+
CASE WHEN percentage = 0.5 THEN 'No Winner' ELSE university END AS winner
47+
FROM cte2
48+
ORDER BY student_count DESC
49+
LIMIT 1
50+
;
51+
```
52+
53+
## Site Solution
54+
55+
```sql
56+
-- LeetCode Solution
57+
SELECT
58+
CASE
59+
WHEN NY.excellent_students > CA.excellent_students THEN 'New York University'
60+
WHEN NY.excellent_students < CA.excellent_students THEN 'California University'
61+
ELSE 'No Winner'
62+
END AS winner
63+
FROM
64+
(
65+
SELECT
66+
COUNT(*) as excellent_students
67+
FROM
68+
NewYork
69+
WHERE
70+
score >= 90
71+
) NY,
72+
(
73+
SELECT
74+
COUNT(*) as excellent_students
75+
FROM
76+
California
77+
WHERE
78+
score >= 90
79+
) CA;
80+
```
81+
82+
## Notes
83+
84+
TBD
85+
86+
## NB
87+
88+
TBD
89+
90+
Go to [Index](../?tab=readme-ov-file#index)\
91+
Go to [Overview](../?tab=readme-ov-file)

0 commit comments

Comments
 (0)