SQL Current Year
The widest of the three DATE_TRUNC-based rolling windows — everything since January 1st of this year.
What & Why
A current-year filter starts on January 1 and uses the next January 1 as its exclusive upper boundary. The worked Queryflo table fixes that range to calendar year 2024.
See How It Works
BUSINESS QUESTION
Using 2024-03-31 as the report date, Marketing wants campaigns whose start date belongs to 2024.
| id | name | channel | spend | start_date | end_date | status | target_segment |
|---|---|---|---|---|---|---|---|
| 1 | Spring Launch | google_ads | 55000.00 | 2024-01-15 | 2024-03-31 | active | smb |
| 2 | Retention Webinar | 45000.00 | 2024-02-10 | 2024-04-15 | active | enterprise | |
| 3 | Finance Retargeting | 50000.00 | 2024-03-12 | 2024-05-31 | active | enterprise | |
| 4 | Enterprise Search | google_ads | 60000.00 | 2024-04-01 | 2024-06-30 | active | enterprise |
EXAMPLE QUERY
SELECT
id AS campaign_id,
name,
start_date
FROM marketing.campaigns
WHERE start_date >= DATE '2024-01-01'
AND start_date < DATE '2025-01-01'
ORDER BY start_date, campaign_id;RESULT — exact output from the displayed Queryflo rows
| campaign_id | name | start_date |
|---|---|---|
| 1 | Spring Launch | 2024-01-15 |
| 2 | Retention Webinar | 2024-02-10 |
| 3 | Finance Retargeting | 2024-03-12 |
| 4 | Enterprise Search | 2024-04-01 |
All displayed campaign start dates belong to the fixed 2024 year window.
Now You Try
Practice this concept
Return campaigns starting in the fixed 2024 calendar year, ordered by start date and campaign id.
Available schema
marketingPrefix tables with marketing.table_name.
campaign_idnamestart_datemarketing.campaigns| Column | Type |
|---|---|
| id | integer |
| name | text |
| channel | text |
| spend | numeric |
| start_date | date |
| end_date | date |
| status | text |
| target_segment | text |
| legacy_id | text |
query.sql
Sign up free to try it on a real business scenario