I have a use case, where the data/orders from source comes everyday also may not on few days. I want to generate the data for all the dates till today as below
| Sales | Order_Qunty | Date |
| ------------ | ------------ | ------------ |
| 20 | 20000 | 20231202 |
| 30 | 30000 | 20231205 |
| 30 | 40000 | 20231207 |
Expected Output
Sales | Order_Qunty | Date |
---|---|---|
20 | 20000 | 20231202 |
0 | 0000 | 20231203 |
0 | 0000 | 20231204 |
30 | 30000 | 20231205 |
0 | 0000 | 20231206 |
30 | 40000 | 20231207 |
0 | 0000 | 20231208 |
0 | 0000 | 20231209 |
0 | 0000 | 20231210 |
0 | 0000 | 20231211 |
0 | 0000 | 20231212 |
I want to Generate the data for each date till today using the above source table and the Date table which has the date range from 19000101 - 20991231 Please Advise
Thanks in advance
2条答案
按热度按时间jm2pwxwz1#
You can use a
LEFT JOIN
between the Date table and the source table. This will fill in missing dates with zeros forSales
andOrder_Quantity
.6jjcrrmo2#
This is implementation of PostgreSQL.
In SqlServer
Please replace your_existing_data to your real table name.