Amazon Interview Question for Software Engineer / Developers






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

@above
What if three employees the same highest salary?

- Thiyaneshwaran S November 11, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It says 3rd max you moron

- Anonymous November 19, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@above ^
I think it should work.

SELECT min(salary) FROM 
(SELECT Distinct TOP 3 salary FROM employee WHERE deptid = <INPUT>)

- Altruist November 11, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

TOP operator eliminates duplicate by default. So, there is no need to use Distinct here.

- Anonymous November 11, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Please ignore it. I am wrong.

- Anonymous November 11, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The absolute right one would be:
SELECT min(salary) FROM
(SELECT Distinct TOP 3 salary FROM employee WHERE deptid = <INPUT>
ORDER BY salary)

- Anonymous November 11, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Actually the above query is wrong too. Missing order by salary "desc".

- Another anonymous November 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi I dont know how you are able to write queries without any tables?

- mousey April 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I tested them on SQL Server:
select d.DeptName,max(e.SALARY) as SALARY from EMPLOYEE e
inner join DEPARTMENT d on e.DeptID = d.DeptID group by d.DeptName;

select MIN(ta.SALARY) from
(select top 3 SALARY from EMPLOYEE e inner join DEPARTMENT d on
e.DeptID = d.DeptID where d.DeptName='Marketing' order by e.SALARY desc) ta;

- Jovi June 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select salary,deptid from employee where salary=(select max(salary) from employee where salary<(select max(salary) from employee
where salary<(select max(salary) from employee)))

just tried! Correct me if i am wrong :)

- aravind646 June 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use Partition by

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

the above answers did not consider the situation that multiple employees may have the same highest salary. here is my answer tested in the mysql:
SELECT temp.max_salary, ssn, dno from employee
inner join
(select max(salary) as max_salary, dno as dnum
from employee
group by dno) temp
where employee. salary = max_salary and employee.dno= temp.dnum

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

Second max salary

select max(salary) from employee where salary != (select max(salary) from employee)

Third max salary
select max(salary) from employee where salary <

(select max(salary) from employee where salary != (select max(salary) from employee))

So on...

- Senthilnathan R A November 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sorry for formatting

Third max salary

select max(salary) from employee where salary <
(select max(salary) from employee where salary != (select max(salary) from employee))

- Senthilnathan R A November 09, 2013 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

In MySQL:
1) SELECT d.deptid, max(e.salary) FROM employee e INNER JOIN department d ON e.deptid = d.deptid GROUP BY d.deptid.
2)SELECT salary FROM employee WHERE deptid = <INPUT> GROUP BY salary DESC LIMIT 2,1;

- Anonymous November 10, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

why do you need a JOIN if you only need to select the department id? Judging by the query here, dept id would have already existed in employee table.

- Anonymous March 24, 2011 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

SQL:
SELECT min(salary) FROM
(SELECT TOP 3 salary FROM employee WHERE deptid = <INPUT>)

- Anonymous November 10, 2009 | 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