PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Data Manipulation (SQL/Python)/Amazon

Compute a Rolling Seven-Day Revenue Sum with Missing Dates

Last updated: Jul 9, 2026

Quick Overview

Solve a PostgreSQL rolling-revenue problem that needs a complete daily series per seller, including no-order dates. It assesses UTC date handling, gap filling, status filters, window semantics, numeric precision, and partial seven-day histories.

  • medium
  • Amazon
  • Data Manipulation (SQL/Python)
  • Data Scientist

Compute a Rolling Seven-Day Revenue Sum with Missing Dates

Company: Amazon

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Technical Screen

The source report identified a hard SQL question about a rolling sum but did not preserve its schema or exact output. The following is a self-contained practice reconstruction of that topic. You have a PostgreSQL table: ```text orders ------ order_id BIGINT PRIMARY KEY seller_id BIGINT NOT NULL ordered_at TIMESTAMPTZ NOT NULL status TEXT NOT NULL -- 'completed', 'cancelled', or 'refunded' amount NUMERIC NOT NULL -- nonnegative order amount ``` Write one PostgreSQL query that returns a daily revenue series for every seller with at least one completed order. For each such seller: - Start the series on that seller's earliest UTC completed-order date. - End the series on that seller's latest UTC completed-order date. - Include every calendar date in between, even when the seller has no completed orders that day. - `daily_revenue` is the sum of `amount` for completed orders on that UTC date; use `0` on a missing date. - `rolling_7d_revenue` is the sum of `daily_revenue` for the current calendar date and the previous six calendar dates. Before a seller has seven dates of history, use all dates available since that seller's series began. - Cancelled and refunded orders contribute nothing. Return exactly these columns: - `order_date` - `seller_id` - `daily_revenue` - `rolling_7d_revenue` The window is based on calendar dates, not the previous seven order rows. Preserve numeric precision and order the final result by `seller_id` ascending and `order_date` ascending.

Quick Answer: Solve a PostgreSQL rolling-revenue problem that needs a complete daily series per seller, including no-order dates. It assesses UTC date handling, gap filling, status filters, window semantics, numeric precision, and partial seven-day histories.

Related Interview Questions

  • Monthly Cohort Retention - Amazon (medium)
  • Find recommended friend pairs by shared songs - Amazon (medium)
  • Find recommended friend pairs by shared listening - Amazon (easy)
  • Write SQL window functions for D7 retention - Amazon (medium)
  • Find daily first-order merchants with SQL - Amazon (medium)
|Home/Data Manipulation (SQL/Python)/Amazon

Compute a Rolling Seven-Day Revenue Sum with Missing Dates

Amazon logo
Amazon
Jun 4, 2026, 12:00 AM
mediumData ScientistTechnical ScreenData Manipulation (SQL/Python)
0
0

The source report identified a hard SQL question about a rolling sum but did not preserve its schema or exact output. The following is a self-contained practice reconstruction of that topic.

You have a PostgreSQL table:

orders
------
order_id    BIGINT       PRIMARY KEY
seller_id   BIGINT       NOT NULL
ordered_at  TIMESTAMPTZ  NOT NULL
status      TEXT         NOT NULL  -- 'completed', 'cancelled', or 'refunded'
amount      NUMERIC      NOT NULL  -- nonnegative order amount

Write one PostgreSQL query that returns a daily revenue series for every seller with at least one completed order. For each such seller:

  • Start the series on that seller's earliest UTC completed-order date.
  • End the series on that seller's latest UTC completed-order date.
  • Include every calendar date in between, even when the seller has no completed orders that day.
  • daily_revenue is the sum of amount for completed orders on that UTC date; use 0 on a missing date.
  • rolling_7d_revenue is the sum of daily_revenue for the current calendar date and the previous six calendar dates. Before a seller has seven dates of history, use all dates available since that seller's series began.
  • Cancelled and refunded orders contribute nothing.

Return exactly these columns:

  • order_date
  • seller_id
  • daily_revenue
  • rolling_7d_revenue

The window is based on calendar dates, not the previous seven order rows. Preserve numeric precision and order the final result by seller_id ascending and order_date ascending.

Loading comments...

Browse More Questions

More Data Manipulation (SQL/Python)•More Amazon•More Data Scientist•Amazon Data Scientist•Amazon Data Manipulation (SQL/Python)•Data Scientist Data Manipulation (SQL/Python)

Write your answer

Your first approved answer each day earns 20 XP.

Sign in to write your answer.
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.