Find first purchase date and latest purchase date
SQL
Hard
2 views
Problem Description
For each customer, show the first time they ordered and the most recent order date. This is a clean use of MIN and MAX.
Sample Test Case
Input:
Orders(customer_id, order_date)
Output:
Rows per customer
Constraints
Think: GROUP BY customer_id
Official Solution
SELECT customer_id, MIN(order_date) AS first_order_date, MAX(order_date) AS last_order_date FROM Orders GROUP BY customer_id;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!