My current SQL code:
SELECT
[Date], [Count]
FROM
Calendar_Table pdv
LEFT JOIN
(SELECT
COUNT([FILE NAME]) AS [Count], [CLOSE DT]
FROM
Production_Table
GROUP BY
[CLOSE DT]) [Group] ON [pdv].[Date] = [Group].[CLOSE DT]
ORDER BY
[Date]
Please see code below. Calendar_Table
is a simple table, 1 row for every date. Production_Table
gives products sold each day. If the left join produces a NULL
, please produce the most recent non-NULL
value.
Current output:
Date | Count
-----------+--------
9/4/2019 | NULL
9/5/2019 | 1
9/6/2019 | 4
9/7/2019 | NULL
9/8/2019 | 7
9/9/2019 | 11
9/10/2019 | NULL
9/11/2019 | 14
9/12/2019 | NULL
9/13/2019 | 19
Desired output:
Date | Count
-----------+--------
9/4/2019 | 0
9/5/2019 | 1
9/6/2019 | 4
9/7/2019 | 4
9/8/2019 | 7
9/9/2019 | 11
9/10/2019 | 11
9/11/2019 | 14
9/12/2019 | 14
9/13/2019 | 19