SQL Server Pivot Table

Here is a example of Pivot table in SQL

Here is my original table
After applying the following pivot query. The result looks like the following picture.


SELECT UserName,[One],[Two],[Three],[Four]
FROM
 (SELECT UserName, class, grade FROM Testing) Tbl
PIVOT
(
 Max(grade)
 FOR Class IN ([One],[Two],[Three],[Four])
) PivotTable