Skip to content

Latest commit

 

History

History
19 lines (18 loc) · 726 Bytes

1321. Restaurant Growth.md

File metadata and controls

19 lines (18 loc) · 726 Bytes

1321. Restaurant Growth

Question Link

Intuition

date_add(min(visited_on), interval 6 day)means that add 6 days to min(visited_on) The syntax:

DATE_ADD(date,INTERVAL expr type)

Code

# Write your MySQL query statement below
select visited_on, (select sum(amount) from Customer where visited_on between date_sub(c.visited_on, interval 6 day) and c.visited_on) amount,
round(
    (select sum(amount)/7 from Customer where visited_on between date_sub(c.visited_on, interval 6 day) and c.visited_on),2) average_amount from Customer c
where visited_on >= (
    select date_add(min(visited_on), interval 6 day) from Customer
) group by visited_on