Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Build a Rolling Sales Forecast

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Build a Rolling Sales Forecast. Start with the requirements and the one table on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

You are asked to build a rolling monthly forecast for Zulily-style demand planning using historical order data. Write a PostgreSQL query that calculates a 3-month rolling forecast for each product category based on prior monthly sales trends and seasonality, then outputs the forecast for the next month after each observed month.

Use the provided transaction history to derive monthly revenue, compare each month to the same month in the prior year when available, and smooth the forecast with a 3-month moving average. The result should show the forecasted month, category, historical baseline, seasonality factor, and final forecast value.

Schema

orders
ColumnTypeDescription
order_idPKINTPrimary key for each order
order_dateDATEDate the order was placed
categoryVARCHAR(50)Merchandise category
net_salesNUMERIC(12,2)Net revenue from the order
channelVARCHAR(20)Sales channel such as app or web
Tablesorders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results