Learn SQL/Intermediate/Date & Time/SQL Current Quarter

SQL Current Quarter

Same pattern as current month, one level wider — DATE_TRUNC('quarter', ...) instead of 'month'.

What & Why

A quarter filter starts at a quarter boundary and ends just before the next one. The worked campaign result uses the fixed Q1 2024 range from January 1 through April 1.

See How It Works

BUSINESS QUESTION

Using 2024-03-31 as the report date, Marketing wants campaigns that started during Q1 2024.

idnamechannelspendstart_dateend_datestatustarget_segment
1Spring Launchgoogle_ads55000.002024-01-152024-03-31activesmb
2Retention Webinaremail45000.002024-02-102024-04-15activeenterprise
3Finance Retargetinglinkedin50000.002024-03-122024-05-31activeenterprise
4Enterprise Searchgoogle_ads60000.002024-04-012024-06-30activeenterprise
EXAMPLE QUERY
SELECT
  id AS campaign_id,
  name,
  start_date
FROM marketing.campaigns
WHERE start_date >= DATE '2024-01-01'
  AND start_date < DATE '2024-04-01'
ORDER BY start_date, campaign_id;
RESULT — exact output from the displayed Queryflo rows
campaign_idnamestart_date
1Spring Launch2024-01-15
2Retention Webinar2024-02-10
3Finance Retargeting2024-03-12

The fixed Q1 boundaries include the January, February, and March campaigns.

Now You Try

Practice this concept

Return campaigns starting in the fixed first quarter of 2024, ordered by start date and campaign id.

Available schema
marketing

Prefix tables with marketing.table_name.

campaign_idnamestart_date
marketing.campaigns
ColumnType
idinteger
nametext
channeltext
spendnumeric
start_datedate
end_datedate
statustext
target_segmenttext
legacy_idtext
query.sql
Intermediate business practice

Sign up free to try it on a real business scenario