SQL Interview Question - Solution (Part - IX) |

  Рет қаралды 1,357

MeanLifeStudies

MeanLifeStudies

Күн бұрын

Пікірлер: 5
@AbhijitPaldeveloper
@AbhijitPaldeveloper 4 ай бұрын
Question: Which customer has visited the same store location twice for consecutive 2 days and next date shopping amount is higher than previous day In mysql SELECT customer_id, amount FROM(SELECT *, lag(date) OVER(PARTITION BY customer_id, location ORDER BY date ASC) as pre_date, lag(amount) OVER(PARTITION BY customer_id, location ORDER BY date ASC) as pre_amount FROM `shopping`) as e WHERE amount>pre_amount AND DATE_ADD(date, INTERVAL -1 DAY) = pre_date;
@MeanLifeStudies
@MeanLifeStudies 4 ай бұрын
Not same store. A location has two different stores. So same location.
@VARUNTEJA73
@VARUNTEJA73 4 ай бұрын
Q. Which customer has visited to store twice and get amount less one compared to another one A. select customer_id,amount from( select store_id,customer_id,amount,count(customer_id)as counts, row_number()over(partition by store_id,customer_id order by amount desc)ranks from shopping group by store_id,customer_id,amount)t1 where t1.ranks=2 order by customer_id Is this right sir ?
@MeanLifeStudies
@MeanLifeStudies 4 ай бұрын
Yes, you are correct theoretically and you extracted the same expected output. But technically speaking all stores are not in the same location. so we should not take them individually in the partition. because in different locations we have different stores. Ex: Hyd: S1,S2, S3,..... and Bang: S1,S2,S3,...... and Chen: S1,S2,S3,... If All stores are in the same location then your answer is perfect. I hope you understand. Well done. You almost solved it.
@VARUNTEJA73
@VARUNTEJA73 4 ай бұрын
@@MeanLifeStudies ok tq sir
The 25 SQL Questions You MUST Know for Data Analyst Interviews
32:47
KSR Datavizon
Рет қаралды 242 М.
Happy birthday to you by Secret Vlog
00:12
Secret Vlog
Рет қаралды 6 МЛН
PIZZA or CHICKEN // Left or Right Challenge
00:18
Hungry FAM
Рет қаралды 16 МЛН
Мама у нас строгая
00:20
VAVAN
Рет қаралды 6 МЛН
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 61 МЛН
3 Solutions to a ITC Infotech SQL Interview Question
20:01
Ankit Bansal
Рет қаралды 12 М.
Happy birthday to you by Secret Vlog
00:12
Secret Vlog
Рет қаралды 6 МЛН