Session-start flag in an online store

Session-start flag in an online store

You are an analyst at the online hypermarket FreshCart. Marketing is preparing per-session conversion metrics, and step one is to label the page-view stream: where one customer visit ends and the next begins. The agreed rule: if STRICTLY more than 30 minutes passed since the same customer's previous view, a new session starts; exactly 30 minutes still belongs to the same session. A customer's very first view always opens a new session. Label every view in page_views with this flag. Return columns: - customer_id — customer identifier; - viewed_at — view time (timestamp, as stored); - is_new_session — boolean: true if this view starts a new session, false otherwise. Sort by customer_id ascending, then viewed_at ascending. ALL views are included, first ones too. Timestamps never repeat within one customer.

Expected output sample

This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables. Your answer must use the same column names as this sample — alias them with AS if needed.

customer_idviewed_atis_new_session
12026-05-03T09:00:00true
12026-05-03T09:10:00false
12026-05-03T09:41:00true
PostgreSQLv16

Your query result will appear here

Focus radio
Paused · SomaFM · Fluid