Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Analyzing Data From a Spreadsheet
00:00
5 left

Analyzing Data From a Spreadsheet

MediumSQL · PostgreSQL

Problem

How would you analyze data from a sample spreadsheet?

Assume the spreadsheet data has been loaded into the provided PostgreSQL tables. Write a query that summarizes January 2025 approved expenses by department and compares activity with each department's monthly budget.

Output

  1. One row per department, including departments with no qualifying expenses.
  2. Return department_name, transaction_count, total_expense, average_expense, monthly_budget, variance_amount, and budget_status.
  3. Include only approved January expenses with non-NULL amounts. Sort by total expense descending, then department name ascending.

Schema

departments
ColumnTypeDescription
department_idPKINTEGERUnique department identifier
department_nameVARCHAR(100)Department name
monthly_budgetNUMERIC(12,2)Monthly expense budget
spreadsheet_expenses
ColumnTypeDescription
expense_idPKINTEGERUnique expense identifier
department_idINTEGERDepartment associated with the expense
expense_dateDATEDate recorded in the spreadsheet
amountNUMERIC(12,2)Expense amount
expense_statusVARCHAR(40)Approval status
expense_typeVARCHAR(60)Expense classification
Tablesdepartmentsspreadsheet_expenses
Interviewer

Your question is Analyzing Data From a Spreadsheet. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.