# Task: 022 **Database:** retails ## Question Show the customer with the highest account balance for each area. ## Gold Query ```sql SELECT c_mktsegment, c_custkey, c_name, c_acctbal FROM ( SELECT c.c_mktsegment, c.c_custkey, c.c_name, c.c_acctbal, RANK() OVER (PARTITION BY c.c_mktsegment ORDER BY c.c_acctbal DESC) AS rn FROM customer c ) t WHERE rn = 1; ``` **Execution Result:** | c_mktsegment | c_custkey | c_name | c_acctbal | |----------------|-------------|--------------------|-------------| | AUTOMOBILE | 21734 | Customer#000021734 | 9998.72 | | BUILDING | 330 | Customer#000000330 | 9999.59 | | FURNITURE | 72823 | Customer#000072823 | 9999.65 | | HOUSEHOLD | 48616 | Customer#000048616 | 9999.84 | | MACHINERY | 14740 | Customer#000014740 | 9999.96 | *5 rows*