Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Duplicate Accounts with Windows

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Duplicate Accounts with Windows. Start with the requirements and the two tables on the right.

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.

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results