Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Compare Current Month Spend vs Budget

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Compare Current Month Spend vs Budget. Read through the requirements and the three tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

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

Problem

You are given monthly spend and budget data. Write a PostgreSQL query that compares actual versus budgeted spend by department for the current month, returning each department’s actual spend, budgeted spend, variance, and variance percentage. Use the current month based on CURRENT_DATE.

Schema

departments
ColumnTypeDescription
department_idPKINTPrimary key for the department
department_nameVARCHAR(100)Department display name
actual_spend
ColumnTypeDescription
spend_idPKINTPrimary key for the spend record
department_idINTReferences the department that incurred the spend
spend_dateDATEDate the spend was recorded
amountDECIMAL(12,2)Actual spend amount
budget_spend
ColumnTypeDescription
budget_idPKINTPrimary key for the budget record
department_idINTReferences the department assigned the budget
budget_monthDATEFirst day of the budget month
budget_amountDECIMAL(12,2)Budgeted spend amount
Tablesdepartmentsactual_spendbudget_spend
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results