Restaurant Growth| Leetcode 1321 | Crack SQL Interviews in 50 Qs #mysql #leetcode

preview_player
Показать описание
Want to crack SQL interviews? Check out our latest video!!!

A 50-questions SQL study plan to ace any interview.
This tutorial will walk you through the solution in easy steps. This is an easy-level question from Leetcode.

Consistency is what transforms average into excellence.
So be consistent & keep Coding💻!!

Timecodes
0:00 - Introduction
0:13 - Question Explanation
1:23 - Understanding Concept with the help of Example
4:12- Writing SQL Query
9:10 - Explanation of SQL Query
10:44 - Outro

Connect With Me -

#coding
#leetcode
#mysql
#sql
#interview
#sqlinterview
#sqlinterviewquestionsandanswers
#sql_server
#learnwithchirag
#restaurant
#growth
Рекомендации по теме
Комментарии
Автор

Hey there! 👋 For more interesting content, tutorials, and updates, Feel free to connect with me on

Instagram Handles :-



Let's stay connected and keep the creativity flowing! 💡

learnwithchirag
Автор

Great explanation, Thanks Here is my try (More Easy Way👍)

with cte as (select visited_on, sum(amount) as amt from Customer group by visited_on)
, cte2 as(SELECT visited_on, sum(amt) over (order by visited_on rows between 6 preceding and current row) as summm FROM cte)
select visited_on, summm as amount, round(summm/7,2) as average_amount from cte2 where visited_on between date_add((select min(visited_on) from Customer), interval 6 day) and (select max(visited_on) from Customer)
order by visited_on

Satish_____Sharma
Автор

Thank you very easy to understand solution without any window function complexity

RupeshBiswas-ns
Автор

WITH CTE AS
(
SELECT VISITED_ON, SUM(AMOUNT) AS AMOUNT
FROM CUSTOMER
GROUP BY VISITED_ON
)
SELECT
VISITED_ON,
SUM(AMOUNT) OVER(ORDER BY VISITED_ON ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS AMOUNT,
ROUND(AVG(AMOUNT*1.0) OVER (ORDER BY VISITED_ON ROWS BETWEEN 6 PRECEDING AND CURRENT ROW), 2) AS AVERAGE_AMOUNT
FROM CTE
ORDER BY VISITED_ON
OFFSET 6 ROWS;

rachit.gulyani
Автор

it would be better if you could also teach the theory part, before solving the question directly. we don't know how subqueries are written. for example: i wrote round function inside the subquery, why is it outside, or when what is done, please explain

harshitagupta
Автор

why did we do sum/7 and not take average directly instead?

avniaggarwal
Автор

EXCELLETN BUT EASY WITH WINDOW FUNCTION.

insidehead
Автор

Hi Chirag
i tried to run queries column by column like your approach in ms sql server
however for visited_on my sub query is returning more than one values which is 7, 8,9,10
which ic expected
how can i modify
with cte as (
select dateadd(day, -6, visited_on) as d from customer
)
select visited_on
from customer where
visited_on >= (select d from cte )
group by visited_on
order by visited_on

vineetjain
Автор

bhai ye SQL ki query ka syntax kitna hard h ye interval vala new syntax aa gya

Abhay
join shbcf.ru