Skip to content

Commit 08f0121

Browse files
authored
Update Winning Candidate.sql
1 parent 907219f commit 08f0121

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Medium/Winning Candidate.sql

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,15 @@ from candidate c inner join cte on c.id = cte.candidateId
6262
where rn = 1
6363

6464

65-
65+
Prac:
66+
with cte as (
67+
select
68+
candidateId,
69+
count(id) as vote_cnt,
70+
rank() over(order by count(id) desc) as rn
71+
from Vote
72+
group by candidateId
73+
)
74+
select b.name
75+
from cte c inner join Candidate b on c.candidateId = b.id
76+
where rn = 1

0 commit comments

Comments
 (0)