ID Allocate
552779 A - Level 2 Tier 1
552779 G - Level 2 Tier 2
552779 O - 4 Units
进入这个
1 2 3
552779 | A - 2级1级| G - 2级第2层| O - 4个单位
答案 0 :(得分:0)
WITH OrderedItems AS (
SELECT ID
,Allocate
,ROW_NUMBER() OVER (PARTITION BY ID ORDER BY Allocate) AS RowNumber
FROM Table
)
SELECT Id
,MAX(CASE WHEN RowNumber = 1 THEN Allocate ELSE NULL END) AS [1]
,MAX(CASE WHEN RowNumber = 2 THEN Allocate ELSE NULL END) AS [2]
...
FROM OrderedItems
GROUP BY Id
如果需要,可以在最后一部分使用数据透视