Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Average Sales Per Month

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

Your question is Average Sales Per Month. 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

Closer Consulting wants a monthly view of sales performance. Write a PostgreSQL query that calculates the average non-null sale amount for each calendar month in the sales table.

Requirements

  1. Group sales by calendar month using the sale date.
  2. Return the month and average sale amount, rounded to two decimal places, ordered chronologically.

AVG should ignore rows where sale_amount is NULL.

Schema

sales
ColumnTypeDescription
sale_idPKINTUnique identifier for the sale
sale_dateDATEDate on which the sale occurred
sale_amountDECIMAL(10,2)Monetary value of the sale
Tablessales
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results