Table Schema
Inspect
Table
| Column | Type |
|---|---|
| license_id | integer |
| user_id | integer |
| expiry_date | date |
Find licenses expiring within the next 7 days.
Table Schema
| Column | Type |
|---|---|
| license_id | integer |
| user_id | integer |
| expiry_date | date |
Sample Data
| license_id | user_id | expiry_date |
|---|---|---|
| 1 | 101 | 2024-02-01 |
| 2 | 102 | 2024-02-05 |
| 3 | 103 | 2024-02-20 |
| 4 | 104 | 2024-02-03 |
| 5 | 105 | 2024-02-10 |
| license_id | user_id |
|---|---|
| 1 | 101 |
| 2 | 102 |
| 4 | 104 |
SQL Editor
| license_id | user_id |
|---|---|
| 1 | 101 |
| 2 | 102 |
| 4 | 104 |
Hints
Solution
Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.
SELECT license_id, user_id FROM licenses WHERE expiry_date BETWEEN DATE '2024-02-01' AND DATE '2024-02-01' + INTERVAL '7 days';
Explanation
Read the expected output columns to determine the final grain.
Aggregate or rank the input rows to calculate the requested metric.
Filter, sort, and alias the final columns to match the output.
Related Questions