Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Trending in AI
Hot
Agentic AI EngineerForward-Deployed EngineerGenAI EngineerAI Architect
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
Group Outstanding Balances by Month and Region
00:00
5 left

Group Outstanding Balances by Month and Region

MediumSQL · PostgreSQL

Problem

SSIS questions Star/ Snowflake Schema Difference

Write a PostgreSQL query against the provided dimensional tables to summarize outstanding loan balances by reporting month and region. The query should preserve fact rows whose branch or region mapping is missing, exclude reporting months outside the first quarter of 2026, and exclude zero-total regions.

Output

  1. One row per reporting month and region
  2. Columns: region_name, reporting_month, total_outstanding_balance, reporting_branches
  3. Sort by month ascending, then region name ascending

Output details

  • Represent missing region mappings as Unassigned in region_name.
  • Treat NULL outstanding_balance values as zero before summing.
  • Count distinct branch_id values for reporting_branches.
  • Include 2026-01-01 and exclude 2026-04-01 when filtering snapshot dates.
  • Format reporting_month as YYYY-MM.

Schema

fact_loan_snapshot
ColumnTypeDescription
snapshot_idPKINTUnique loan snapshot record identifier
branch_idINTBranch associated with the snapshot
snapshot_dateDATEDate on which the balance was recorded
outstanding_balanceDECIMAL(12,2)Outstanding loan balance at the snapshot date
dim_branch
ColumnTypeDescription
branch_idPKINTUnique branch identifier
branch_nameVARCHAR(100)Branch display name
region_idINTNormalized region identifier
dim_region
ColumnTypeDescription
region_idPKINTUnique region identifier
region_nameVARCHAR(100)Region display name
Tablesfact_loan_snapshotdim_branchdim_region
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.