Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Quarterly Expense Forecast Rollup

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

Your question is Quarterly Expense Forecast Rollup. Start with the requirements and the two tables 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.

Quarterly Expense Rollup

Problem

You are given raw expense transactions and a quarterly forecast table. Your task is to structure the expense data into a quarter-level report that a VP can review quickly. The output should compare posted actual spend against forecasted spend by quarter and department, and include the variance between them.

Tables

Expenses
Name

expense_id

Type

INT

Description

Primary key for each expense row

Name

expense_date

Type

DATE

Description

Date the expense was incurred

Name

department

Type

VARCHAR(50)

Description

Cost center or department name

Name

amount

Type

DECIMAL(12,2)

Description

Expense amount; may be negative for credits

Name

status

Type

VARCHAR(20)

Description

Posting status such as posted, pending, or void

Quarter forecast
Name

forecast_quarter

Type

DATE

Description

Quarter start date used as the forecast key

Name

department

Type

VARCHAR(50)

Description

Department name

Name

forecast_amount

Type

DECIMAL(12,2)

Description

Planned quarterly spend

Representative Rows

expenses
12024-01-05Marketing1200posted
42024-04-02Sales900pending
72024-06-30Finance-50posted
102024-08-01Engineering2000posted
quarter_forecast
2024-01-01Marketing2500
2024-04-01Finance500
2024-07-01Engineering2200
2024-10-01Legal300
Tablesexpensesquarter_forecast
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results