I have been trying to get the number of customers who bought the first time, 2nd time and 3rd time over 12 months period. Like this:
I have found a similar script that shows the repeat customers but there is no splitting over the months or times. How can i get count of customers per day by unique and repeat customer for specific date?
SELECT a.OrderDate, a.first, (b.total - a.first) AS repeated FROM
(SELECT OrderDate, COUNT(q1.CustomerID) AS first FROM
(SELECT CustomerID, min(OrderDate) AS OrderDate FROM orders GROUP BY CustomerID)q1 GROUP BY q1.OrderDate)a
JOIN
(SELECT OrderDate, COUNT(OrderNumber) AS total FROM orders GROUP BY OrderDate)b
on(a.OrderDate = b.OrderDate)
Here is the sample data:
I am beginner for sql and have been trying to modify for a few days.
Thank you!