Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

Here is the query, let me know if you need any further details,....

Select CustomerName, Sum(Isnull(Sale_Price,price))
From OrdersItems OI 
Join OrderTable O on OI.order_fk = O.order_fk
Join Customer C on C.custom_fk=O.custom_fk
Where 
	DATEDIFF(mm,order_date, getdate() ) < 6
Group By CustomerName

- Jai December 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The tricky part of this question is that the sale price value, which isn't a "not-null", may not in the table. When a sale-Price is not null, you can do a sum calculation with its value. When a sale_price is null, you can't calculate a sum with its value.

- fz December 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Check for null and assign 0 for such columns. I have updated the query...

- Jai December 07, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

When sale_price is null, the calculation needs to use the price value.

- fz December 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

I have modified the statement to include Price when the Sales_price is null.. Check it out...

- Jai December 08, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Select CustomerName, Sum(Isnull(Sale_Price,price))
From OrdersItems OI
Join OrderTable O on OI.order_fk = O.order_fk
Join Customer C on C.custom_fk=O.custom_fk
Where
DATEDIFF(mm,order_date, getdate() ) <= 6
Group By CustomerName

- Anonymous January 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Select CustomerName, Sum(Isnull(Sale_Price,price))
From OrdersItems OI
Join OrderTable O on OI.order_fk = O.order_fk
Join Customer C on C.custom_fk=O.custom_fk
Where
DATEDIFF(mm,order_date, getdate() ) <= 6
Group By CustomerName

- Anonymous January 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

SELECT customerid, SUM(totalprice), MIN(orderdate)
FROM orders
WHERE totalprice IS NOT NULL AND orderdate >= DATE_SUB(CURDATE(), INTERVAL 90 DAY)
GROUP BY customerid;

- jack March 31, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

SELECT C.id, sum(OI.sale_price) FROM Customer C JOIN Order O ON (C.id=O.custom_fk) JOIN OrderItem OI ON (OI.order_fk=O.id) WHERE SELECT DATEDIFF(MONTH, now(), O.order_date) <= 6;

- droidxlabs November 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

SELECT cust_id, SUM(totalprice)
FROM orders
WHERE totalprice IS NOT NULL AND Order_Date between to_char(sysdate,'MM') and to_char(sysdate,'MM')-6
GROUP BY cust_id;

- Nikhil August 01, 2017 | 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