SQL server has a
PIVOT
function which "flattens" out rows of data into columns. The syntax for the statement has at least one
unpivoted columns and then multiple columns which are
pivoted based on that (unpivoted column).
@digimanus has an article on how to create a
Dynamic Pivot which utilizes a data
CUBE
for more advanced queries which may be needed with some datasets.
For your particular question, I cannot determine what the pivot point is; so I cannot provide a code-answer. The "data" you have provided seems to be incomplete; you are showing one data table but the queries you have are referencing two separate tables.
References
MSDN:
Using PIVOT and UNPIVOT - SQL Server | Microsoft Docs[
^]
Digimanus article:
Dynamic Pivoting with Cubes and eventhandlers in SQL Server 2005, 2008 and 2008 R2[
^]