I saw sometimes you can use a cross apply, but I feel it won't work in this case as I have 10 columns for "Days" (for 10 years) and 10 columns for "Discharges" (for 10 years).....so I need this pivoted into 10 different row per zip and age group.
Starting output:
Zipcode | Age | 2022 Days | 2023 Days | 2022 Discharges | 2023 Discharges |
---|---|---|---|---|---|
12345 | 1-10 | 1 | 2 | 3 | 4 |
12345 | 11-20 | 5 | 6 | 7 | 8 |
Desired output:
Zipcode | Age | Year | Days | Discharges |
---|---|---|---|---|
12345 | 1-10 | 2022 | 1 | 2 |
12345 | 1-10 | 2023 | 3 | 4 |
12345 | 11-20 | 2022 | 5 | 6 |
12345 | 11-20 | 2022 | 7 | 8 |
The top is essentially what I have (Just only kept 2022 and 2023, but will really be 2022 - 2032).
Is it possible to do two unpivots, a cross apply or something else to achieve this? This is also a realllllllly large dataset (1.5 billion rows), so I'll have to do it in batches, but would rather not do one unpivot, and then another unpivot.
Thanks in advance!