#201

New Customers Per Day

MEDIUMTime-series & PartitionsPOSTGRESQL

Problem Description

You are building a daily new customer cohort report for an e-commerce acquisition analytics pipeline. Each day, the growth team needs to know how many brand-new customers placed their first order — this metric drives CAC (customer acquisition cost) calculations, cohort retention models, and paid marketing attribution dashboards. Given a table of orders with customer IDs and order dates, count the number of new customers acquired on each day. **New Customer Definition:** A customer is considered new on a given date if and only if that date equals their earliest order date across all orders ever placed. Formally, a customer is new on date `d` if `d = MIN(order_date)` across all their orders in the table. Customers who ordered on a previous day and re-order on a later day are returning customers and must be excluded from that later day's count. Return one row per calendar day that has at least one new customer, with columns: - `date` — the calendar date (type: DATE) - `new_customer_count` — the number of distinct customers whose first-ever order falls on that date Order the results by `date` ascending.

Topics

time seriesaggregation

Asked at Companies

lyft

Solve This Problem

Sign up to access the interactive code editor, run test cases, view the editorial, and get AI-powered feedback on your solution.

Start Solving →