Given a table Customers that contains customer information including their customer ID, year, and revenue data, write a SQL solution to find all customers who had positive revenue in the year 2021.
Note: Revenue can be negative, so we only want customers where revenue > 0 for the year 2021.
Return the result table in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
customer_id
PK
|
int | Unique identifier for each customer |
year
PK
|
int | The year of the revenue record |
revenue
|
int | Customer revenue for that year (can be negative) |
Input & Output
| customer_id | year | revenue |
|---|---|---|
| 1 | 2021 | 1000 |
| 2 | 2021 | -1000 |
| 3 | 2020 | 2000 |
| 1 | 2020 | 4000 |
| customer_id |
|---|
| 1 |
Only customer 1 has positive revenue in 2021 (1000). Customer 2 has negative revenue in 2021 (-1000), and customer 3's positive revenue is from 2020, not 2021.
| customer_id | year | revenue |
|---|---|---|
| 1 | 2021 | -500 |
| 2 | 2021 | 0 |
| 3 | 2020 | 1000 |
| customer_id |
|---|
No customers have positive revenue in 2021. Customer 1 has negative revenue, customer 2 has zero revenue (not positive), and customer 3's positive revenue is from 2020.
| customer_id | year | revenue |
|---|---|---|
| 1 | 2021 | 500 |
| 2 | 2021 | 1500 |
| 3 | 2021 | 200 |
| customer_id |
|---|
| 1 |
| 2 |
| 3 |
All three customers have positive revenue in 2021, so all customer IDs are returned in the result.
Constraints
-
1 ≤ customer_id ≤ 100000 -
2000 ≤ year ≤ 2025 -
-1000000 ≤ revenue ≤ 1000000