由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请教SQL面试题
相关主题
google 面试题疑问GOOGLE 电面面经
SQL 面试题,请高手指点各产业 BONUS 差别
初级SQL问题请教一道面试题
求问一道面试题的答案CS 面试题总结(4)
想问问哪里可以找到DB或者SQL的面试题?嗨,发个牢骚
请教SQL Query 面试题How to design the sql for this problem? (转载)
请教SQL问题一道sql
被一个面试题卡的泪流满面 SQL问个sql问题
相关话题的讨论汇总
话题: name话题: votes话题: candidate话题: count
进入JobHunting版参与讨论
1 (共1页)
o*********b
发帖数: 13
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
h*******3
发帖数: 52
2
我试着写了一个,用的是 implicit join
select Name from Candidate c,
(select CandidateId from votes order by count(CandidateId) desc limit 1 )
votes
where c.Id = votes.CandidateId.
会不会看起来更加清楚些。

【在 o*********b 的大作中提到】
: 我自己感觉我做对了 但是面我的烙印非说不对 我把我的答案贴在这里
: 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

o*********b
发帖数: 13
3
请问
select CandidateId from votes order by count(CandidateId) desc
count(CandidateId)什么意思? 难道是产生 每个CandidateId的频率统计? 我的理
解是 count(CandidateId)产生CandidateId到底有多少个distinct value?

【在 h*******3 的大作中提到】
: 我试着写了一个,用的是 implicit join
: select Name from Candidate c,
: (select CandidateId from votes order by count(CandidateId) desc limit 1 )
: votes
: where c.Id = votes.CandidateId.
: 会不会看起来更加清楚些。

h*******3
发帖数: 52
4
有个地方需要 clarify 一下,就是 votes 表中一个Id对应多个 CandidateId ,
语法应该是?
select count(id) IDs, CandidateId from votes group by CandidateId order by
IDs desc

【在 o*********b 的大作中提到】
: 请问
: select CandidateId from votes order by count(CandidateId) desc
: count(CandidateId)什么意思? 难道是产生 每个CandidateId的频率统计? 我的理
: 解是 count(CandidateId)产生CandidateId到底有多少个distinct value?

o*********b
发帖数: 13
5
你刚开始的那个答案应该是不对的吧?
但是我的答案没有错误啊

【在 h*******3 的大作中提到】
: 有个地方需要 clarify 一下,就是 votes 表中一个Id对应多个 CandidateId ,
: 语法应该是?
: select count(id) IDs, CandidateId from votes group by CandidateId order by
: IDs desc

b******u
发帖数: 81
6
会不会是因为存在并列第一?
1 (共1页)
进入JobHunting版参与讨论
相关主题
问个sql问题想问问哪里可以找到DB或者SQL的面试题?
SQL面题,大家练练吧请教SQL Query 面试题
Bank Financial Developer Position请教SQL问题
F家DS,analytics电面面经,贡献一个sql相关被一个面试题卡的泪流满面 SQL
google 面试题疑问GOOGLE 电面面经
SQL 面试题,请高手指点各产业 BONUS 差别
初级SQL问题请教一道面试题
求问一道面试题的答案CS 面试题总结(4)
相关话题的讨论汇总
话题: name话题: votes话题: candidate话题: count