Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
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 feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Average Sales by Category SQL
00:00
5 left

Average Sales by Category SQL

EasySQL · PostgreSQL

Problem

Business Context

Quantiphi's commerce analytics team needs category-level sales benchmarks for product performance reporting. Categories with no completed sales should remain visible for dashboard completeness.

Task

Write a PostgreSQL query that calculates the average completed sale value for each product category during Q1 2025. A sale's value is quantity * unit_price.

Requirements

  1. Join products to sales by product_id and retain categories with no qualifying sales.
  2. Include only sales with status completed and a sale date from 2025-01-01 through 2025-03-31.
  3. Return the category, number of completed sale rows, and average sale value rounded to two decimal places. Ignore NULL sale values using PostgreSQL aggregate behavior.
  4. Sort the output alphabetically by category.

Schema

products
ColumnTypeDescription
product_idPKINTEGERUnique product identifier
product_nameVARCHAR(100)Product name
categoryVARCHAR(50)Product category
sales
ColumnTypeDescription
sale_idPKINTEGERUnique sale identifier
product_idINTEGERProduct associated with the sale
sale_dateDATEDate on which the sale occurred
statusVARCHAR(20)Sale processing status
quantityINTEGERNumber of units sold
unit_priceNUMERIC(10,2)Price for one unit
Tablesproductssales
Interviewer

Your question is Average Sales by Category SQL. 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.