SQL Count Of Open Orders Each Day Between Two Dates

后端 未结 4 1147
感情败类
感情败类 2020-12-21 04:38

I\'ve tried searching but it\'s likely I\'m using the wrong keywords as I can\'t find an answer.

I\'m trying to find the number of orders that are open between two d

4条回答
  •  [愿得一人]
    2020-12-21 05:07

    Join Dates to the result of the join between Employees and Orders, then group by dates and employees to obtain the counts, something like this:

    SELECT
      d.Date,
      o.Employee,
      COUNT(*) AS count
    FROM Employees e
      INNER JOIN Orders o ON e.ID = o.Employee
      INNER JOIN Dates d ON d.Date BETWEEN o.Opened AND o.Closed
    GROUP BY
      d.Date,
      o.Employee
    

提交回复
热议问题