SQL 枢轴 table,在标准上有多个枢轴

SQL Pivot table, with multiple pivots on criteria

这是我的数据集,

它有一个预留(唯一 ID)一个 reservation_dt 一个财政年度(大部分是同一年)月份,数字和名称以及预留状态然后它有总预留数量通过柜台(基本上 每个预订行 1 个)

这些是我的指导方针(它们需要按月变成列)

我希望将其转化为一个枢轴 table,这是我目前所掌握的,但无法弄清楚为什么它不起作用。

我想我会使用 sum(total_number_Requested) 或 count(total_requested) 将上述每条指南变成一列,其中保留状态为...等等。 我愿意接受关于如何使它更简单并使其发挥作用的任何其他想法。

SELECT [month_name],
       fyear AS fyear,
       Requested,
       Num_Requested
FROM (SELECT reservation,
             reservation_status,
             total_number_requested,
             fyear,
             [month_name],
             [month],
             total_requested
      FROM #temp2) SourceTable
PIVOT (SUM(total_number_requested)
       FOR reservation_status IN ([Requested])) PivotNumbRequested PIVOT(COUNT(reservation)
       FOR total_requested IN ([Num_Requested])) PivotCountRequested
WHERE [month] = 7
ORDER BY fyear,
         [month];

使用条件表达式模拟数据透视。示例:

SELECT fyear, Month, Monthname, Count(*) AS CountALL, Sum(total_number_requested) AS TotNum, 
Sum(IIf(reservation_status = "Order Created", total_number_Requested, Null)) AS SumCreated
FROM tablename
GROUP BY fyear, Month, MonthName

更多信息:
SQLServer - Multiple PIVOT on same columns