Skip to content
Advertisement

how to convert a table to another in SQL (similar to pivot, but not exactly)

I have a database table looks like this in the below, in SQL Server 2016:

(the max rows for the same ProjectKey is 3)

I want to write a query to be able to convert the above table to the following:

If it can be achieved by writing a SQL query that would be great. Anyone can help? Thank you very much!

Advertisement

Answer

You can use row_number() and conditional aggregation:

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