Premium customers, accounts and money in
The task
Relationship managers review every customer in the 'premium' segment. A customer can have several accounts, and each account has many transactions.
Return one row per premium customer:
customer_idfull_nameaccounts: how many accounts the customer has (open or closed), 0 if nonemoney_in: the sum of the positive transaction amounts across all of their accounts, 0 if there are none
Sort by money_in descending, then customer_id ascending.
Expected output
customer_idfull_nameaccountsmoney_in- Sorted by money_in descending, then customer_id ascending.
- Checked on the sample and on 2 hidden datasets. How grading works
Tables Digital bank · click a name to insert it
customers70 rows in the sample
One row per customer. Key: customer_id.
| int | Unique id. | |
| text | Name. | |
| date | Day they became a customer. | |
| text | retail, premium or business. |
accounts126 rows in the sample
One row per account. A customer can have several. Key: account_id.
| int | Unique id. | |
| int | Owner. | |
| text | checking, savings or credit. | |
| date | Opening day. | |
| date | Closing day. NULL while open. |
transactions9,906 rows in the sample
One row per posted transaction. Positive amounts are money in, negative are money out. Key: txn_id.
| bigint | Unique id. | |
| int | The account. | |
| timestamp | When it posted (UTC). | |
| numeric(12,2) | Signed amount, USD. | |
| text | salary, rent, groceries, dining, travel, transfer, fees or refund. | |
| text | Merchant name. NULL for salary, transfers and fees. |
Related questions
- Completed trips for every city and vehicle typemedium
- Daily spend against sign-ups for one campaignhard
- Kitchen revenue by customer country, four tablesmedium
- Open accounts at each month end, by account typehard
- Refund value of wrong-item returns by categoryeasy
- Sign-ups per campaign who placed a large ordereasy
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL