Apple Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

select customer_id, sum(expense) as se
from table
group by customer_id
order by se desc
limit 5

- myarycn September 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

select customer_id
from (select customer_id,sum(expenses) as exp
from table_name
group by customer_id,product_id)
orderby exp
where rownum<=5

- NIC August 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Good thinking, I think you need to put the last row outside of a subquery, as:
select * from
(select customer_id
from (select customer_id,sum(expenses) as exp
from table_name
group by customer_id,product_id)
orderby exp )
where rownum<=5

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

select customer_id, sum(expenses) as sum_exp where rownum <= 5 group by customer_id order by sum_exp desc;

- Sourabh Das August 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Rownum should be used after rows have been fetched.

- TwoHeadedMonkey September 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

rownum is checked after rows have been fetched.

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

select top 5
customerid
, sum(expenses) as ep
from testexpense
group by customerid
order by ep desc

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

select customer_id,sum(expenses) from Customer
group by customer_id
order by sum(expenses) desc

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

select top 5 CustomerId,Sum(Expenses) from expenses group by CustomerId order by SUM(Expenses) desc

- thamarai.rajendran January 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select top 5 CustomerId,Sum(Expenses) from expenses group by CustomerId order by SUM(Expenses) desc

- thamarai.rajendran January 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In MySQL:

set @currRank := 0;
select * from (
select customerid, total_exp, @currRank := @currRank + 1 as exp_rank from
(select customerid, sum(totalexpense) as total_exp from expenses
group by customerid) X order by total_exp desc) Y where exp_rank <= 5

- manish.bhoge March 01, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

SELECT customer_id,SUM(expenses) AS s_exp FROM Customer GROUP BY customer_id ORDER BY s_exp DESC LIMIT 5;

- Pooja Karadgi July 22, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select * from (select custid,sum(exp) from table group by custid) where rownum<=5;

- kranti Ingale November 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

select distinct B.customer_id from (
select A.customer_id,rank(A.total_expenses) over(order by A.total_expenses desc) as Ranks from (
select customer_id,sum(expenses) as total_expenses from customer
group by customer_id ) A ) B
where B.Ranks <=5

- itsmeashishsingh February 07, 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