SQL Extract Week

Returns the ISO week number of the year — week 1 through 52 (occasionally 53).

What & Why

EXTRACT(WEEK FROM date_column) returns the ISO 8601 week number — a standardized way of numbering weeks within a year, where week 1 is the week containing the year's first Thursday.

See How It Works

BUSINESS QUESTION

Growth wants event volume by ISO week.

iduser_idevent_namecreated_atproperties
1001101signup2024-01-15 09:12:00+00{"source":"organic"}
1002101activated2024-01-16 14:25:00+00{"step":"workspace"}
1003102signup2024-02-10 11:08:00+00{"source":"paid"}
1004103report_viewed2024-03-12 16:40:00+00{"report":"retention"}
EXAMPLE QUERY
SELECT
  EXTRACT(WEEK FROM created_at)::int AS event_week,
  COUNT(*) AS events
FROM growth.events
GROUP BY event_week
ORDER BY event_week;
RESULT — exact output from the displayed Queryflo rows
event_weekevents
32
61
111

The January 15 and 16 events share ISO week 3.

Intermediate business practice

Sign up free to try it on a real business scenario