Interview Question

Data Engineer Interview

-

Meta

Write a query that returns product_family, units_sold, percentage of promoted.

AnswerAdd Tags

Interview Answers

2 Answers

4

I gave interview today. Thanks for adding these questions. I got same questions. similar to this but I small changes to case statement and/or join: select product_family, sum(units_sold), sum(case when s.promotion_id != 0 then 1 else 0 end)*100.0/count(1) as prct_promoted from sales s left join products p on s.product_id = p.product_id left join product_classes pc on p.product_class_id = ps.product_class_id join promotions prm on s.promotion_id = prm.promotion_id group by product_family;

Anonymous on

0

Something like this: select pc.product_family, sum(s.units_sold), ROUND(sum(case when s.promotion_id 0 then 1 else 0 end)*100.0/ count(s.product_id), 2) as percent_promoted from sales s left join products p on s.product_id = p.product_id left join product_classes pc on p.product_class_id = pc.product_class_id group by pc.product_family

Anonymous on

Add Answers or Comments

To comment on this, Sign In or Sign Up.