Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Detect Recurring Expense Recording Issues

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

Welcome to the SQL screen.

The question is on your right: Detect Recurring Expense Recording Issues. 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 expense transactions, category metadata, and recording rules. Your task is to identify expense categories that show a recurring recording issue in the last 90 days: categories with at least 3 invalid expenses and an invalid rate above 25%. Return the category name, total expense count, invalid expense count, and invalid rate, sorted by the highest invalid rate.

Schema

expense_categories
ColumnTypeDescription
category_idPKINTPrimary key for the expense category
category_nameVARCHAR(100)Human-readable category name
active_flagBOOLEANWhether the category is active
expenses
ColumnTypeDescription
expense_idPKINTPrimary key for the expense record
category_idINTForeign key to expense_categories.category_id
expense_dateDATEDate the expense was recorded
amountNUMERIC(12,2)Expense amount
statusVARCHAR(20)Recorded status such as approved, pending, or invalid
expense_rules
ColumnTypeDescription
statusPKVARCHAR(20)Status value allowed by the recording policy
is_allowedBOOLEANWhether the status is allowed
Tablesexpense_categoriesexpensesexpense_rules
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results