Spending by merchant partner group, NULL merchants included
The task
Partnerships keeps a small lookup of merchants and the group each belongs to:
merchant |
partner_group |
|---|---|
'FreshCart' |
'grocery_partner' |
'Cafe Uno' |
'dining_partner' |
'SkyAir' |
'travel_partner' |
| NULL | 'internal' |
The last row is deliberate: transactions with no merchant (transfers and fees) are internal. Any other merchant that is not in the lookup belongs to the group 'other'.
Look at money going out: transactions with amount < 0 (zero amounts and money in are ignored). For each partner group that has at least one such transaction, return:
partner_grouptransactions: how many of themtotal_out: their total as a positive number
Sort by total_out descending, then partner_group ascending.
Expected output
partner_grouptransactionstotal_out- Sorted by total_out descending, then partner_group 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
- April spend and cost per click for search and socialeasy
- Email-referred customers and their completed orderseasy
- Headcount by department, empty and unassigned includedeasy
- Invoiced amount by the plan active on the issue datemedium
- Open accounts at each month end, by account typehard
- Premium customers, accounts and money inmedium
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL