Ai
1 Star 0 Fork 0

逸扬/leetcode-hub-mysql

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
lc-0574.test 1.12 KB
Copy Edit Raw Blame History
逸扬 authored 2022-05-01 21:45 +08:00 . 512-534-574-577-578-579-585-596-597-601 (10)
# $574. 当选者
# https://leetcode-cn.com/problems/winning-candidate/
# SQL架构
Create table If Not Exists Candidate (id int, name varchar(255));
Create table If Not Exists Vote (id int, candidateId int);
Truncate table Candidate;
insert into Candidate (id, name) values ('1', 'A');
insert into Candidate (id, name) values ('2', 'B');
insert into Candidate (id, name) values ('3', 'C');
insert into Candidate (id, name) values ('4', 'D');
insert into Candidate (id, name) values ('5', 'E');
Truncate table Vote;
insert into Vote (id, candidateId) values ('1', '2');
insert into Vote (id, candidateId) values ('2', '4');
insert into Vote (id, candidateId) values ('3', '3');
insert into Vote (id, candidateId) values ('4', '2');
insert into Vote (id, candidateId) values ('5', '5');
# Write your MySQL query statement below
select
c.name
from
(
select
candidateId as id
from
Vote
group by
candidateId
order by
count(id) desc
limit
1
) tmp
join Candidate c on tmp.id = c.id;
# clean-up
drop table Candidate;
drop table Vote;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gdut_yy/leetcode-hub-mysql.git
git@gitee.com:gdut_yy/leetcode-hub-mysql.git
gdut_yy
leetcode-hub-mysql
leetcode-hub-mysql
master

Search