Infibeam Interview Question for SDE-2s


Country: India
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
1
of 1 vote

select a.name,b.cnt from candidate a,
         (select * from 
              (select candid,count(1) cnt from votes group by candid order by cnt desc)x 
                     where rownum=1) b 
    where a.id=b.candid

it just returns the name of the winner and the votes he got

- narasimha June 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use this query:

select v.CandidateId, max(v.Num) as Votes from
(select CandidateId, count(CandidateId) as Num from Vote group by CandidateId) v
group by v.CandidateId

- Eric Lei April 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

oh no, copied incorrect script. should be this one:

select c.Name, count(c.Name) as Votes from Candidate c
join Vote v
on c.Id = v.CandidateId
group by c.Name
order by COUNT(c.Name) desc

- Eric Lei April 30, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

select Name as winner  from candidate 
where id = (
select CandidateId from vote group  by CandidateId order by count(CandidateId) desc limit 1)

- vijay.edella May 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

SELECT name AS winner FROM candidate WHERE ID = (SELECT candidateId FROM vote GROUP BY candidateid ORDER BY COUNT(*) DESC LIMIT 1) AS S

- andycuisong September 19, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select name from Candidate where ID in
(select candidate_ID from Vote
group by candidate_ID having count(*) in
(select max(c) from
(select count(*) c from Vote group by candidate_ID))

- jwei.aiesec.tju September 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select name from Candidate where ID in
(select candidate_ID from Vote
group by candidate_ID having count(*) in
(select max(c) from
(select count(*) c from Vote group by candidate_ID))

- jwei.aiesec.tju September 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select name from candidate, vote where candidate.Id=vote.Id group by CandidateId having max(CandidateId) IN ( select count(CandidateId) from vote);

- Pranav August 06, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select
id from 
(select top 1 candidateid as id, count(id) as votes
from vote 
group by candidateid
order by votes desc
) as a

- Niraj August 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

;with cte
as
(
select *, row_number() over (partition by CandidateID order by CandidateID) as rn
from VoterTable
)
select top 1 *, B.CandidateName from cte A
inner join CandidateTable B on A.CandidateId=B.CandidateID
order by rn desc

- Anonymous April 09, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

SELECT candidate.Name
FROM candidate
join( SELECT count(*) as 'Total_Votes', v.candidateid 
                                                            FROM  vote v
                                                            GROUP BY v.candidateid
                                                            ORDER BY Total_Votes DESC
                                                             Limit 1)b on candidate.id = b.candidateid

- sun May 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

asd;slld

- sun May 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Oracle SQL code

SELECT candidateid, name
from(
SELECT v.candidateid, c.name , count(v.id) num_of_votes
FROM candidate c, vote v
WHERE c.id = v.candidateid
Group by v.candidateid
Order by count(v.id) desc) 
where rownum = 1
;

- monika.m.srivastava June 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select cand.name from (

select cand.name, vote.cand_id, count(vote.id) as count_vote from
vote join
cand on vote.cand_id = cand.id

group by cand.name, vote.cand_id

) as a
order by a.count_vote desc limit 1;

- AR February 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select * from (
  
 select cand.name, vote.cand_id, count(vote.id) as count_vote from 
  vote join 
  cand on vote.cand_id = cand.id
  
  group by cand.name, vote.cand_id
 
  ) as a
  order by a.count_vote desc limit 1;

- AR February 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select name from candidate where id=(select candidate_id from vote group by(candidate_id) order by count(candidate_id) desc limit 1);

- Anonymous July 26, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select name from candidate where id=(select candidate_id from vote group by(candidate_id) order by count(candidate_id) desc limit 1);

- Anonymous July 26, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select c.condidateId,c.name as condidate_name,count(v.Id) as no_of_votes from vote v
inner join candidate c
on v.candidateId=c.id
group by c.condidateId,c.name
having no_of_votes=(select max(no_of_votes) from (
select condidateId,count(Id) as no_of_votes from vote group by condidateId) A)

OR

select c.condidateId,c.name as condidate_name,count(v.Id) as no_of_votes from vote v
inner join candidate c
on v.candidateId=c.id
group by c.condidateId,c.name
having no_of_votes=(select condidateId,count(Id) as no_of_votes from vote group by condidateId order by no_of_votes desc limit 1)

- itsmeashishsingh February 08, 2019 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More