For example, I need to change from
to
.
I know PIVOT is for that, but it requires an aggregate function; and for my case, I donot need to aggregate only need column to row.
You can use the following sample data:
CREATE TABLE[StudentScores]
(
[UserName] NVARCHAR(20),
[Subject] NVARCHAR(30),
[Score]FLOAT,
)
GO
INSERT INTO[StudentScores]SELECT'Nick','Chinese',80
INSERT INTO[StudentScores]SELECT'Nick','Maths',90
INSERT INTO[StudentScores]SELECT'Nick','English',70
INSERT INTO[StudentScores]SELECT'Nick','Biology',85
INSERT INTO[StudentScores]SELECT'Kent','Chinese',80
INSERT INTO[StudentScores]SELECT'Kent','Maths',90
INSERT INTO[StudentScores]SELECT'Kent','English',70
INSERT INTO[StudentScores]SELECT'Kent','Biology',85