Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
SQL Anomaly Detection with Aggregations
00:00
5 left

SQL Anomaly Detection with Aggregations

MediumSQL · PostgreSQL

Problem

Huntington's Data Analytics team is reviewing posted debit card activity for unusual daily transaction totals by branch. Write a PostgreSQL query to identify branch dates where the daily transaction amount is unusually high or low compared with that branch's observed daily average.

Requirements

  1. Join branches, accounts, and card_transactions using their keys, and include only posted transactions from January 2025.
  2. Aggregate transactions by branch and transaction date, returning transaction count and total amount.
  3. Calculate each branch's average observed daily amount using a CTE.
  4. Flag a day as high_amount when its total exceeds 150% of the branch average, or low_amount when it is below 50%. Return only anomalous days, ordered by branch and date.

Schema

branches
ColumnTypeDescription
branch_idPKINTHuntington branch identifier
branch_nameVARCHAR(100)Branch name
accounts
ColumnTypeDescription
account_idPKINTAccount identifier
branch_idINTBranch where the account was opened
card_transactions
ColumnTypeDescription
transaction_idPKINTTransaction identifier
account_idINTAccount associated with the transaction
transaction_dateDATETransaction date
amountDECIMAL(10,2)Transaction amount
transaction_statusVARCHAR(20)Transaction processing status
Tablesbranchesaccountscard_transactions
Interviewer

Your question is SQL Anomaly Detection with Aggregations. Start with the requirements and the three 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.