Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8f85f7a

Browse files
add 574
1 parent 0e4d50a commit 8f85f7a

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ Your ideas/fixes/algorithms are more than welcome!
609609
|584|[Find Customer Referee](https://leetcode.com/problems/find-customer-referee/)|[Solution](../master/database/_584.java) | || Easy|
610610
|580|[Count Student Number in Departments](https://leetcode.com/problems/count-student-number-in-departments/)|[Solution](../master/database/_580.sql) | || Medium | Left Join
611611
|577|[Employee Bonus](https://leetcode.com/problems/employee-bonus/)|[Solution](../master/database/_577.sql) | || Easy |
612+
|574|[Winning Candidate](https://leetcode.com/problems/winning-candidate/)|[Solution](../master/database/_574.sql) | || Medium |
612613
|197|[Rising Temperature](https://leetcode.com/problems/rising-temperature/)|[Solution](../master/database/_197.sql)| O(n^2)|O(n) | Easy|
613614
|196|[Delete Duplicate Emails](https://leetcode.com/problems/delete-duplicate-emails/)|[Solution](../master/database/_196.sql)| O(n^2)|O(n) | Easy|
614615
|184|[Department Highest Salary](https://leetcode.com/problems/department-highest-salary)|[Solution](../master/database/_184.sql)| O(n^2)|O(n) | Medium|

database/_574.sql

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--574. Winning Candidate
2+
--Table: Candidate
3+
--
4+
--+-----+---------+
5+
--| id | Name |
6+
--+-----+---------+
7+
--| 1 | A |
8+
--| 2 | B |
9+
--| 3 | C |
10+
--| 4 | D |
11+
--| 5 | E |
12+
--+-----+---------+
13+
--Table: Vote
14+
--
15+
--+-----+--------------+
16+
--| id | CandidateId |
17+
--+-----+--------------+
18+
--| 1 | 2 |
19+
--| 2 | 4 |
20+
--| 3 | 3 |
21+
--| 4 | 2 |
22+
--| 5 | 5 |
23+
--+-----+--------------+
24+
--id is the auto-increment primary key,
25+
--CandidateId is the id appeared in Candidate table.
26+
--Write a sql to find the name of the winning candidate, the above example will return the winner B.
27+
--
28+
--+------+
29+
--| Name |
30+
--+------+
31+
--| B |
32+
--+------+
33+
--Notes:
34+
--You may assume there is no tie, in other words there will be at most one winning candidate.
35+
36+
select Name from Candidate as Name where id =
37+
(select CandidateId from Vote group by CandidateId order by count(CandidateId) desc limit 1);

0 commit comments

Comments
 (0)