Loading problem...
An online marketplace tracks account registrations, order transactions, and item metadata using three relational tables:
users columns:
orders columns:
items columns:
Task:
Output requirements:
Supported submission environments:
users:
| user_id | join_date | favorite_brand |
|---------|------------|----------------|
| 1 | 2018-01-01 | Lenovo |
| 2 | 2018-02-09 | Samsung |
| 3 | 2018-01-19 | LG |
| 4 | 2018-05-21 | HP |
orders:
| order_id | order_date | item_id | buyer_id | seller_id |
|----------|-------------|---------|----------|-----------|
| 1 | 2019-08-01 | 4 | 1 | 2 |
| 2 | 2018-08-02 | 2 | 1 | 3 |
| 3 | 2019-08-03 | 3 | 2 | 3 |
| 4 | 2018-08-04 | 1 | 4 | 2 |
| 5 | 2018-08-04 | 1 | 3 | 4 |
| 6 | 2019-08-05 | 2 | 2 | 4 |
items:
| item_id | item_brand |
|---------|------------|
| 1 | Samsung |
| 2 | Lenovo |
| 3 | LG |
| 4 | HP |[
{"buyer_id":1,"join_date":"2018-01-01","orders_in_2019":1},
{"buyer_id":2,"join_date":"2018-02-09","orders_in_2019":2},
{"buyer_id":3,"join_date":"2018-01-19","orders_in_2019":0},
{"buyer_id":4,"join_date":"2018-05-21","orders_in_2019":0}
]Each row is keyed by users.user_id. Only orders where the user appears as buyer and order_date is in 2019 are counted.
users:
| user_id | join_date | favorite_brand |
|---------|------------|----------------|
| 10 | 2019-01-01 | Apex |
| 11 | 2019-03-11 | Nova |
| 12 | 2019-07-15 | Flux |
orders:
| order_id | order_date | item_id | buyer_id | seller_id |
|----------|-------------|---------|----------|-----------|
| 101 | 2019-01-01 | 1 | 10 | 11 |
| 102 | 2019-12-31 | 1 | 10 | 12 |
| 103 | 2020-01-01 | 2 | 10 | 11 |
| 104 | 2019-06-15 | 2 | 11 | 10 |
items:
| item_id | item_brand |
|---------|------------|
| 1 | Apex |
| 2 | Nova |[
{"buyer_id":10,"join_date":"2019-01-01","orders_in_2019":2},
{"buyer_id":11,"join_date":"2019-03-11","orders_in_2019":1},
{"buyer_id":12,"join_date":"2019-07-15","orders_in_2019":0}
]Both 2019-01-01 and 2019-12-31 are inside the target year. 2020-01-01 is excluded.
users:
| user_id | join_date | favorite_brand |
|---------|------------|----------------|
| 21 | 2017-09-10 | Arbor |
| 22 | 2018-02-05 | Pixel |
orders:
| order_id | order_date | item_id | buyer_id | seller_id |
|----------|-------------|---------|----------|-----------|
| 900 | 2018-12-31 | 7 | 21 | 22 |
| 901 | 2020-01-01 | 8 | 22 | 21 |
items:
| item_id | item_brand |
|---------|------------|
| 7 | Arbor |
| 8 | Pixel |[
{"buyer_id":21,"join_date":"2017-09-10","orders_in_2019":0},
{"buyer_id":22,"join_date":"2018-02-05","orders_in_2019":0}
]Every user must appear even when no qualifying 2019 purchase exists.
Constraints