## Walmart Labs Interview Question for SDE-3s

Country: United States

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

``````WITH cte_prices AS (
SELECT pc.product_id,
pc.price,
ROW_NUMBER(
PARTITION BY pc.product_id
ORDER BY pc.time DESC) AS rowNumber
FROM price_changes pc
WHERE pc.time <= @t1 )
SELECT cp.product_id,
cp.price
FROM cte_prices cp
WHERE cp.rowNumber = 1;``````

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

Correction: The window function should be ROW_NUMBER() OVER (...

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

SELECT PRODUCT_ID,PRICE FROM
(
SELECT S.*,
RANK() OVER (PARTITION BY PRODUCT_ID ORDER BY PRICE_TIME DESC) RANKING
FROM PRODUCT_SALES S
WHERE S.PRICE_TIME < SYSDATE-2
) WHERE RANKING=1;

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

``select product, price, max(time) from product where time <= <time> group by product;``

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

SELECT p, c FROM price where t<=6 GROUP BY p;

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

``SELECT p, c FROM price where t<=6 GROUP BY p;``

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

``````select * from (
select product_id,
price,
row_number() over (partition by product_id order by price_time desc) rown
from product_sales where price_time <= '06-Apr-2019') where rown = 1;``````

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

here a is productid b is price and c is time

select i.a,i.b from t5 i inner join
(select A,max(c) as c from t5 where c <=6 group by A ) j
on i.a = j.a and i.c=j.c

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

what if product has been updated on same timestamp multiple times?

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.

### 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.