I have the input data: I want to calculate the standard deviation such that the missing dates values of item_demand should be taken as 0.
Input Data:
+---+---------------+-------------+
| | checkout_date | item_demand |
+---+---------------+-------------+
| 0 | 2022-08-02 | 1 |
| 1 | 2022-08-05 | 2 |
| 2 | 2022-08-07 | 1 |
| 3 | 2022-08-08 | 1 |
| 4 | 2022-08-09 | 1 |
| 5 | 2022-08-12 | 2 |
+---+---------------+-------------+
I used inbuilt function :
cast(stddev(item_demand) as dec(14,2)) deviation
But since some of my dates are missing the inbuilt function won't give a proper result; I want to take into account the missing dates (with item_demand as 0 ) also, and then I want the standard deviation.
Please suggest how to achieve this. I'm new to SQL