Skip to content

Commit ee55df1

Browse files
refactor 574
1 parent 8f048fa commit ee55df1

File tree

1 file changed

+0
-35
lines changed

1 file changed

+0
-35
lines changed

Diff for: database/_574.sql

-35
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,2 @@
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-
361
select Name from Candidate as Name where id =
372
(select CandidateId from Vote group by CandidateId order by count(CandidateId) desc limit 1);

0 commit comments

Comments
 (0)