Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Rolling Three-Month Average Query
00:00
5 left

Rolling Three-Month Average Query

MediumSQL · PostgreSQL

Problem

Teradata Vantage reporting needs a monthly sales trend for active sales regions. Write a PostgreSQL-compatible SQL query that calculates monthly sales and a rolling three-month average for each active region from January through April 2025.

Requirements

  1. Aggregate transaction amounts by region and calendar month.
  2. Include months with no transactions as zero sales.
  3. Calculate the average for the current month and up to the two preceding calendar months within each region.
  4. Return results ordered by region name and month.

Schema

regions
ColumnTypeDescription
region_idPKINTUnique identifier for a sales region
region_nameVARCHAR(100)Display name of the sales region
is_activeBOOLEANWhether the region is included in reporting
sales_transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
region_idINTRegion associated with the transaction
sale_dateDATEDate on which the sale occurred
amountDECIMAL(12,2)Sales amount, which may be NULL
Tablesregionssales_transactions
Interviewer

Your question is Rolling Three-Month Average Query. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.