不用
PIVOT关键字就可以轻松完成此 *** 作,只需将其分组即可
select P.ProfileID, min(case when PD.PropertyName = 'FirstName' then P.PropertyValue else null end) as FirstName, min(case when PD.PropertyName = 'LastName' then P.PropertyValue else null end) as LastName, min(case when PD.PropertyName = 'Salary' then P.PropertyValue else null end) as Salaryfrom Profiles as P left outer join PropertyDefinitions as PD on PD.PropertyDefinitionID = P.PropertyDefinitionIDgroup by P.ProfileID
您也可以使用
PIVOT关键字执行此 *** 作
select *from( select P.ProfileID, P.PropertyValue, PD.PropertyName from Profiles as P left outer join PropertyDefinitions as PD on PD.PropertyDefinitionID = P.PropertyDefinitionID) as P pivot ( min(P.PropertyValue) for P.PropertyName in ([FirstName], [LastName], [Salary]) ) as PIV
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)