Report Seven-Day Revenue Totals and Averages

Quick Overview

Report total revenue and average daily revenue for each complete seven-day restaurant window.

Report Seven-Day Revenue Totals and Averages

Company: Meta

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

### Problem Report visited_on, amount and average_amount for each complete seven-day window ending on visited_on. amount sums all customer payments over that day and the preceding six days; average_amount divides by7 and rounds to two decimals. At least one customer visits on every calendar date between the first and last recorded visits. Visit dates are finite. A NULL payment contributes zero to recorded revenue, and the visit still counts toward daily coverage. Sort visited_on ascending. ### Tables Table: `Customer` ```text +---------------+---------+ | Column Name | Type | +---------------+---------+ | customer_id | int | | name | varchar | | visited_on | date | | amount | int | +---------------+---------+ In SQL,(customer_id, visited_on) is the primary key for this table. This table contains data about customer transactions in a restaurant. visited_on is the date on which the customer with ID (customer_id) has visited the restaurant. amount is the total paid by a customer. ``` ### Example ```text Customer (customer_id,name,visited_on,amount): (1,A,2021-01-01,10), (1,A,2021-01-02,20), (1,A,2021-01-03,30), (1,A,2021-01-04,40), (1,A,2021-01-05,50), (1,A,2021-01-06,60), (1,A,2021-01-07,70), (2,B,2021-01-07,7), (1,A,2021-01-08,80) Output (visited_on,amount,average_amount): (2021-01-07,287,41.00), (2021-01-08,357,51.00) ``` ### What a Strong Answer Covers - Include every payment recorded on each of the seven calendar dates. - Return only complete windows and preserve the required date order and rounding. ### Follow-up Questions - How would you report every day if the restaurant sometimes closed? - How would you calculate the same metrics separately for each location?

Overview: Report total revenue and average daily revenue for each complete seven-day restaurant window.

Meta logo
Meta
mediumSoftware EngineerOtherData Manipulation (SQL/Python)
0
0

Problem

Report visited_on, amount and average_amount for each complete seven-day window ending on visited_on. amount sums all customer payments over that day and the preceding six days; average_amount divides by7 and rounds to two decimals. At least one customer visits on every calendar date between the first and last recorded visits. Visit dates are finite. A NULL payment contributes zero to recorded revenue, and the visit still counts toward daily coverage. Sort visited_on ascending.

Tables

Table: Customer

+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| customer_id   | int     |
| name          | varchar |
| visited_on    | date    |
| amount        | int     |
+---------------+---------+
In SQL,(customer_id, visited_on) is the primary key for this table.
This table contains data about customer transactions in a restaurant.
visited_on is the date on which the customer with ID (customer_id) has visited the restaurant.
amount is the total paid by a customer.

Example

Customer (customer_id,name,visited_on,amount):
(1,A,2021-01-01,10), (1,A,2021-01-02,20), (1,A,2021-01-03,30), (1,A,2021-01-04,40), (1,A,2021-01-05,50), (1,A,2021-01-06,60), (1,A,2021-01-07,70), (2,B,2021-01-07,7), (1,A,2021-01-08,80)
Output (visited_on,amount,average_amount): (2021-01-07,287,41.00), (2021-01-08,357,51.00)

What a Strong Answer Covers Guidance

  • Include every payment recorded on each of the seven calendar dates.
  • Return only complete windows and preserve the required date order and rounding.

Follow-up Questions Guidance

  • How would you report every day if the restaurant sometimes closed?
  • How would you calculate the same metrics separately for each location?