Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 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
Build my plan
SQL Duplicate Accounts with Windows
00:00
5 left

SQL Duplicate Accounts with Windows

HardSQL · PostgreSQL

Problem

AllianceBernstein's client data is consolidated from multiple customer systems, so the same investor may appear under different capitalization, spacing, or phone formatting. Write a PostgreSQL query to identify active investment accounts belonging to duplicate customer profiles.

Requirements

  1. Join customer profiles to investment accounts.
  2. Normalize email addresses and phone numbers before comparing profiles.
  3. Use window functions to return every active account in a duplicate group, including the duplicate count and a deterministic rank.
  4. Exclude records with missing matching fields, inactive accounts, and profiles that do not belong to a duplicate group.

Schema

customer_profiles
ColumnTypeDescription
profile_idPKINTCustomer profile identifier
legal_nameVARCHAR(255)Customer's legal name
emailVARCHAR(255)Customer email address
phoneVARCHAR(40)Customer phone number
source_systemVARCHAR(50)Originating customer system
investment_accounts
ColumnTypeDescription
account_idPKINTInvestment account identifier
profile_idINTRelated customer profile
account_numberVARCHAR(30)Account number
account_typeVARCHAR(30)Account classification
statusVARCHAR(20)Account status
opened_onDATEAccount opening date
Tablescustomer_profilesinvestment_accounts
Interviewer

Your question is SQL Duplicate Accounts with Windows. Start with the requirements and the two 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.