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
Calling the result column count was a bit odd because it seems to be in fact a row number. You can do that by using ROW_NUMBER.
The other interesting part is that you also want open date and close date as separate rows. Using a simple UNION will solve that.
WITH cte
AS (SELECT Row_number() OVER ( PARTITION BY employee
ORDER BY order_ref) count,
employee,
opened,
closed
FROM orders)
SELECT employee, opened date, count
FROM cte
UNION ALL
SELECT employee, closed date, count
FROM cte
ORDER BY Date,
employee
DEMO