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.

Exemplo de resposta esperada

É assim que se parece uma resposta correta: ela tem seu próprio número de linhas e não precisa coincidir com as tabelas do esquema. Sua resposta precisa retornar os mesmos nomes de colunas do exemplo: use AS para renomeá-las se for preciso.

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

O resultado da sua consulta aparecerá aqui

Focus radio
Paused · SomaFM · Fluid