例如,我需要从如何在sql server 2005/8中创建没有聚合函数的Column to Row?
改变
。
我知道PIVOT就是为了这个,但它需要一个聚合函数;对于我的情况,我不需要聚合只需要列到行。如果有将是一个创纪录的主题,你可以使用MIN或MAX
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
所以你实际上想要多列名为'80','90','70','85'?或者你是否在为每个用户名寻找一行,每一列都是主题?在这种情况下,@OMG小马的答案可以满足你的需求,而且你可以看到你确实需要一个聚合。 – 2010-10-26 04:35:40