I wrote a joint query which returns the following data:
ProductCode | DataName | DataValue | Date |
---|---|---|---|
Code1 | DN1 | DV1 | Date1 |
Code1 | DN2 | DV2 | Date1 |
Code1 | DN3 | DV3 | Date1 |
Code1 | DN4 | DV4 | Date1 |
Code1 | DN5 | DV5 | Date1 |
… | ... | DV6 | ... |
Code2 | DN1 | …. | Date2 |
Code2 | DN3 | Date2 | |
Code2 | DN4 | Date2 | |
…. | ... | ... |
I want to reshape it to the following format:
ProductCode | DN1 | DN2 | DN3 | … | Date |
---|---|---|---|---|---|
Code1 | DV1 | DV2 | DV3 | …. | Date1 |
Code2 | DV1 | DV2 | DV3 | …. | Date2 |
I tried to use PIVOT but it seems to be irrelevant in this case since I don’t need any aggregations. My first question is how should I reshapre the table to the format that I need.