Skip to main content
All Problems
hard0% acceptance

Rank Customers by Net Worth

Rank all customers by their total net worth (sum of all account balances minus sum of all active loan principals). Return first_name, last_name, total_balance, total_loan_principal, net_worth, and a dense_rank (net_worth_rank). Use CTEs and window functions. Include customers even if they have no loans (treat as 0). Order by net_worth_rank ascending.

Schema

🔑idINT
first_nameTEXT
last_nameTEXT
emailTEXT
phoneTEXTNULL
date_of_birthTEXT
cityTEXT
stateTEXT
countryTEXT
created_atTIMESTAMP
postgresql

Run your query to see results

Press Ctrl + Enter to execute