Skip to content
Advertisement

Pivot(transpose) by some columns SQL

I’m looking to transpose by some columns in my table. I have something like the following example:

I would like to have transposed the information to show 1 day per line and the rest of the information as is, I understand this will create several more lines, but would help keeping more clear the information.

right each line show 1 week and then the 7 days of that week, and the amount of hours allocated to each day per project (let’s say by colX value). I was trying to transpose only by the days, but I’m not getting how to use the pivot for only a few values.

Advertisement

Answer

Here’s an example with your data:

See the microsoft documentation for more details on using unpivot.

The output looks like this: enter image description here

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement