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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
Customer Transactions SQL Query
00:00
5 left

Customer Transactions SQL Query

MediumSQL · PostgreSQL

Problem

Continental Finance wants to identify customers showing concentrated monthly transaction activity. Write a PostgreSQL query that reports customers with more than three completed transactions in a calendar month, using only transactions linked to active accounts.

Requirements

  1. Join customers, accounts, and transactions.
  2. Include only transactions from active accounts with completed status.
  3. Group transactions by customer and calendar month using PostgreSQL date functions.
  4. Return the customer, month, transaction count, and total amount. Treat a NULL amount as zero.
  5. Keep only groups with more than three transactions and order by total amount descending.

Output details

  • Return customer_id, customer_name, month_start, transaction_count, and total_transaction_amount, in that order.
  • Represent each calendar month as its first day in month_start.
  • After sorting by total_transaction_amount descending, break ties by customer_id ascending.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer full name
accounts
ColumnTypeDescription
account_idPKINTUnique account identifier
customer_idINTCustomer who owns the account
account_statusVARCHAR(20)Current account status
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
account_idINTAccount associated with the transaction
transaction_dateDATEDate the transaction occurred
statusVARCHAR(20)Transaction processing status
amountNUMERIC(12,2)Transaction amount, which may be NULL
Tablescustomersaccountstransactions
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.