Let's say I have this table on MS SQL Server: Where I am trying to find the total numbers of active users per month of a specific year.
My database is a mess so some active users from December 2022 are being count as January and February 2023.
| Year | Month | Active_Users |
| ------------ | ------------ | ------------ |
| 2022 | 1 | 123 |
| 2022 | 2 | 143 |
| ... | ... | ... |
| 2022 | 12 | 100 |
| 2023 | 1 | 79 |
| 2023 | 2 | 3 |
How do I get the active users values from 2023 month 1 and 2 and add it to 2022 month 12 so I get a table like that:
Year | Month | Active_Users |
---|---|---|
2022 | 1 | 123 |
2022 | 2 | 143 |
... | ... | ... |
2022 | 12 | 182 |
For any value greater than 2022 in the year column, the active users number should be added to active users in December 2022.
2条答案
按热度按时间6yt4nkrj1#
You can use 2 parts of script
monwx1rj2#
You can add the sum of all active users as to the active users of month 12 as you get a scalar value
fiddle