请教SQL面试题# JobHunting - 待字闺中
o*b
1 楼
我自己感觉我做对了 但是面我的烙印非说不对 我把我的答案贴在这里
Given two tables
1. Candidate: Id , Name
2. Vote: Id, CandidateId(this is the id being voted)
Give query to give the name of the winning candidate
我的答案 因为也没有指定具体那个SQL 所以我认为把logic回答出了就可以了
select Name, Votes from (
select c.Name as Name, count(v.Id) as Votes
from Candidate c join Vote v on c.Id = v.CandidateId
group by c.Name
order by COUNT(v.Id) desc )
limit 1
Given two tables
1. Candidate: Id , Name
2. Vote: Id, CandidateId(this is the id being voted)
Give query to give the name of the winning candidate
我的答案 因为也没有指定具体那个SQL 所以我认为把logic回答出了就可以了
select Name, Votes from (
select c.Name as Name, count(v.Id) as Votes
from Candidate c join Vote v on c.Id = v.CandidateId
group by c.Name
order by COUNT(v.Id) desc )
limit 1