Back to problems

Write SQL for recent customer activity

SQL · Point72 · Medium

Write one ANSI SQL query that returns one row for every customer who has at least one historical order with status COMPLETED or SHIPPED. For each such customer, produce these columns: last_order_ts: the largest order_ts among all historical COMPLETED and SHIPPED orders, formatted as YYYY-MM-DD HH24:MI:SS. distinct_products_last_7d: the number of distinct product_id values purchased in qualifying orders inside the rolling 7-day window. net_spend_last_7d: the sum of qty *…

Checking your access…