OrderDateでグループ化することにより、1日あたりの合計注文数を取得できます:
SELECT OrderDate, COUNT(OrderNumber) AS total FROM orders GROUP BY OrderDate
そして、あなたはノーを得ることができます。次のクエリからの1日あたりの最初の注文の数:
SELECT OrderDate, COUNT(q1.CustomerID) AS first FROM (SELECT CustomerID, min(OrderDate) AS OrderDate FROM orders GROUP BY CustomerID)q1 GROUP BY q1.OrderDate
次に、OrderDateでこれら2つを結合して、最初の注文と繰り返しの注文の分布を取得します:
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)