Skip to content
Advertisement

Reformatting SQL output

I have data that looks like this

If I use

I will get

At the moment, I’m retrieving the data in this form and using some C coding to format it like

Assuming that there will always be entries for 10, 20, 30, 40 for every name, is something like this possible in SQL without creating a new table like in SQL Reformatting table columns

Advertisement

Answer

You need to use PIVOT to get your desired results. Before using PIVOT, some customization required in your value in column XX so that the final column output can meet your expectation.

Output-

The same output can be also achieved with this following query-

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