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
- Join customer profiles to investment accounts.
- Normalize email addresses and phone numbers before comparing profiles.
- Use window functions to return every active account in a duplicate group, including the duplicate count and a deterministic rank.
- Exclude records with missing matching fields, inactive accounts, and profiles that do not belong to a duplicate group.