File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -609,6 +609,7 @@ Your ideas/fixes/algorithms are more than welcome!
609
609
| 584| [ Find Customer Referee] ( https://leetcode.com/problems/find-customer-referee/ ) | [ Solution] ( ../master/database/_584.java ) | || Easy|
610
610
|580|[ Count Student Number in Departments] ( https://leetcode.com/problems/count-student-number-in-departments/ ) |[ Solution] ( ../master/database/_580.sql ) | || Medium | Left Join
611
611
| 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 |
612
613
| 197| [ Rising Temperature] ( https://leetcode.com/problems/rising-temperature/ ) | [ Solution] ( ../master/database/_197.sql ) | O(n^2)| O(n) | Easy|
613
614
| 196| [ Delete Duplicate Emails] ( https://leetcode.com/problems/delete-duplicate-emails/ ) | [ Solution] ( ../master/database/_196.sql ) | O(n^2)| O(n) | Easy|
614
615
| 184| [ Department Highest Salary] ( https://leetcode.com/problems/department-highest-salary ) | [ Solution] ( ../master/database/_184.sql ) | O(n^2)| O(n) | Medium|
Original file line number Diff line number Diff line change
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 );
You can’t perform that action at this time.
0 commit comments