SignPost Interview Question for Software Engineer / Developers


Country: United States




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

select rides.name, count(*) as votes from persons left join rides on persons.favorite_ride_id = rides.id group by persons.favorite_ride_id order by votes limit 10;

- afk September 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

* order by votes desc limit 10;

- afk September 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

When I tried this code in Postgres, it gives me this error:
ERROR: column "rides.name" must appear in the GROUP BY clause or be used in an aggregate function

- glide November 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
3
of 3 vote

SELECT rid.name, cnt.votes
FROM rides AS rid
  INNER JOIN
    (
	  SELECT favorite_ride_id, count(1) AS votes
	  FROM persons
	  GROUP BY favorite_rid_id
    ) AS cnt
        ON cnt.favorite_ride_id = rid.id
ORDER BY cnt.votes DESC

- rarcega September 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Just change that to SELECT TOP 10 rid.name, ...

- Anonymous September 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

SELECT rides.name, COUNT(persons.favorite_ride_id) AS votes FROM persons INNER JOIN rides ON persons.`favorite_ride_id`=rides.`id`
GROUP BY rides.`id` ORDER BY COUNT(persons.favorite_ride_id) DESC LIMIT 10;

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

SELECT persons.first_name, persons.last_name, rides.name
  FROM persons
  INNER JOIN rides
    ON rides.id = persons.favorite_ride_id
  INNER JOIN
  (
    SELECT persons.favorite_ride_id, COUNT(*) AS num_votes
    FROM persons
    GROUP BY persons.favorite_ride_id
    ORDER BY num_votes DESC
    LIMIT 10
  ) AS top
  ON top.favorite_ride_id = persons.favorite_ride_id
  ORDER BY top.num_votes DESC;

- anonymouse September 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You could optimize this a bit by not using the additional select in the inner join. You could just select the top 10 results, Grouped By favorite_ride_id and just do an inner join to your ride table.

- Code Guy September 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

sel r.name,count(*) as votes from rides r
     left join persons p on
     r.id=p.favorite_ride_id group by votes order by votes desc limit 10

Pls correct me if i m wrong

- dileep October 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

it shud be

group by r.name

- dileep October 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

select top(10) r.name, count(r.id) as vote
from Persons P INNER JOIN Rides R
ON P.favorite_ride_id = R.id
group by name
order by vote desc

Please tell me, if it is correct.

- Piyush Bajaj November 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select top 10 count(pr.favRideId), fr.Name from Person pr inner join FavRides fr
on pr.favRideId = fr.id 
group by fr.Name
order by count(pr.favRideId) desc

- Niraj November 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select r.name,s.votes from rides r,(select id,count(*) as votes from persons group by id desc) s where s.id=r.id limit 10;

- Rati January 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

SELECT * FROM (SELECT r.name, COUNT(r.id) AS votes FROM persons p, rides r WHERE p.favourite_ride_id = r.id GROUP BY r.id) AS inner_table ORDER BY votes DESC

- 2010prashant September 20, 2013 | 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