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
Common SQL Code Patterns
00:00
5 left

Common SQL Code Patterns

MediumSQL · PostgreSQL

Problem

What are some common codes in SQL?

For this exercise, write a query using the provided account and transaction tables. Include eligible accounts even when they have no qualifying transactions, classify their activity, and handle missing transaction amounts.

Output

  1. One row per active account opened on or before 2025-01-31
  2. Columns: account_id, account_name, transaction_count, total_amount, and activity_code
  3. Include only transactions posted during January 2025
  4. Sort by total_amount descending, then account_id ascending

Schema

accounts
ColumnTypeDescription
account_idPKINTUnique account identifier
account_nameVARCHAR(100)Account holder name
statusVARCHAR(20)Current account status
opened_atDATEDate the account was opened
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
account_idINTAccount associated with the transaction
posted_atDATEDate the transaction was posted
amountDECIMAL(12,2)Transaction amount
transaction_typeVARCHAR(30)Transaction classification
Tablesaccountstransactions
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the two 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.