Total Contractor Payments by Country for January 2025

Quick Overview

Write a SQL query that totals contractor payments per country for January 2025 and ranks the countries by that total. It tests joining payments to contractors, filtering an inclusive date window, grouping by country, and ordering with a tiebreaker.

Total Contractor Payments by Country for January 2025

Company: Deel

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Report the total amount paid per country for payments with `payment_date` from `2025-01-01` through `2025-01-31` inclusive. Return `country` and `total_amount`, ordered by `total_amount` descending, then `country` ascending. ```hint Check both ends of the window A payment dated 2025-01-31 belongs in the report and one dated 2025-02-01 does not. Make sure your date condition treats both edges that way. ``` ### Input Table(s) Table `Contractors`: | Column | Type | Meaning | |---|---|---| | `contractor_id` | INT | Contractor identifier | | `country` | VARCHAR(64) | Contractor's country, not null | Key: `contractor_id` is the primary key. Table `Payments`: | Column | Type | Meaning | |---|---|---| | `payment_id` | INT | Payment identifier | | `contractor_id` | INT | Contractor who was paid, not null | | `amount` | DECIMAL(12,2) | Amount paid, not null and non-negative | | `payment_date` | DATE | Date of the payment, not null | Keys: `payment_id` is the primary key. Every `contractor_id` matches a row in `Contractors`. ### Output Contract - Columns, in this order: `country`, `total_amount`. - One row per country that has at least one payment dated from 2025-01-01 through 2025-01-31. - `total_amount` is the sum of `amount` over those payments, returned with two decimal places and no further rounding. - Sorted by `total_amount` descending, then `country` ascending. Each country appears once, so the order is fully determined. ### Example `Contractors`: | contractor_id | country | |---|---| | 1 | US | | 2 | DE | | 3 | US | | 4 | BR | | 5 | IN | `Payments`: | payment_id | contractor_id | amount | payment_date | |---|---|---|---| | 101 | 1 | 1000.00 | 2025-01-05 | | 102 | 3 | 500.00 | 2025-01-31 | | 103 | 2 | 1500.00 | 2025-01-15 | | 104 | 4 | 700.00 | 2025-02-01 | | 105 | 4 | 800.00 | 2024-12-31 | | 106 | 5 | 900.00 | 2025-01-01 | | 107 | 2 | 0.00 | 2025-01-20 | Expected result: | country | total_amount | |---|---| | DE | 1500.00 | | US | 1500.00 | | IN | 900.00 | US adds two contractors' payments (1000.00 and 500.00), and DE adds 1500.00 and 0.00, so both total 1500.00 and are ordered by country name. Both BR payments fall outside January 2025, so BR has no row. ### Constraints and Clarifications - `Contractors` has between 1 and 10,000 rows, and `Payments` has between 1 and 100,000 rows. - `amount` is non-negative, and no column used here is NULL. - Every `contractor_id` in `Payments` exists in `Contractors`. - Both ends of the window are inclusive. `payment_date` is a `DATE`, with no time of day. - A country with no payment in the window does not appear; there are no rows with a zero total for missing countries. - Payments to several contractors in the same country add into one row for that country. A payment of 0.00 inside the window still counts.

Overview: Write a SQL query that totals contractor payments per country for January 2025 and ranks the countries by that total. It tests joining payments to contractors, filtering an inclusive date window, grouping by country, and ordering with a tiebreaker.

Deel logo
Deel
Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Report the total amount paid per country for payments with payment_date from 2025-01-01 through 2025-01-31 inclusive. Return country and total_amount, ordered by total_amount descending, then country ascending.

Input Table(s)

Table Contractors:

ColumnTypeMeaning
contractor_idINTContractor identifier
countryVARCHAR(64)Contractor's country, not null

Key: contractor_id is the primary key.

Table Payments:

ColumnTypeMeaning
payment_idINTPayment identifier
contractor_idINTContractor who was paid, not null
amountDECIMAL(12,2)Amount paid, not null and non-negative
payment_dateDATEDate of the payment, not null

Keys: payment_id is the primary key. Every contractor_id matches a row in Contractors.

Output Contract

  • Columns, in this order: country , total_amount .
  • One row per country that has at least one payment dated from 2025-01-01 through 2025-01-31.
  • total_amount is the sum of amount over those payments, returned with two decimal places and no further rounding.
  • Sorted by total_amount descending, then country ascending. Each country appears once, so the order is fully determined.

Example

Contractors:

contractor_idcountry
1US
2DE
3US
4BR
5IN

Payments:

payment_idcontractor_idamountpayment_date
10111000.002025-01-05
1023500.002025-01-31
10321500.002025-01-15
1044700.002025-02-01
1054800.002024-12-31
1065900.002025-01-01
10720.002025-01-20

Expected result:

countrytotal_amount
DE1500.00
US1500.00
IN900.00

US adds two contractors' payments (1000.00 and 500.00), and DE adds 1500.00 and 0.00, so both total 1500.00 and are ordered by country name. Both BR payments fall outside January 2025, so BR has no row.

Constraints and Clarifications

  • Contractors has between 1 and 10,000 rows, and Payments has between 1 and 100,000 rows.
  • amount is non-negative, and no column used here is NULL.
  • Every contractor_id in Payments exists in Contractors .
  • Both ends of the window are inclusive. payment_date is a DATE , with no time of day.
  • A country with no payment in the window does not appear; there are no rows with a zero total for missing countries.
  • Payments to several contractors in the same country add into one row for that country. A payment of 0.00 inside the window still counts.