且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Server 2008 - 以一列为中心,按另一列分组,保持对第三列的引用

更新时间:2022-12-09 21:47:05

这是一个非常简单的支点.只是:

That's a very straightforward pivot. Just:

SELECT OperationSessionRecordID, [32],[34],[38]
FROM TEMPtable
  PIVOT (
  min(DebriefingQuestionResults)
  for questionid in ([32], [34], [36])
) AS PIV;

您无需执行任何特殊操作即可通过 OperationSessionRecordID 获得分组 - 基本上,PIVOT 中未提及的每一列都是分组列.

You don't need to do anything special to get the grouping by OperationSessionRecordID - essentially, every column not mentioned in the PIVOT is a grouping column.