我想基于数据透视表格式的每月周期时间创建报告。 通过将Time转换为Integer,我尝试使用下面的Query执行相同的操作。但在报告中,我无法以时间格式显示它。 我将Time数据类型转换为Integer,因为Pivot Table仅允许聚合值。 Average_Cycle_Time在"时间"数据类型和Average_Cycle_Time_I位于"整数"。
示例数据: Station Month Average_Cycle_Time AA 4月12:22:00 AA May 22:16:00 BB 4月16:06:00 BB May 05:30:00
预期成果: 站4月5月 AA 12:22:00 22:16:00 BB 16:06:00 05:30:00
然而,我得到的结果如下: 站4月5月 AA 122200 221600 BB 160600 53000
这里是用于获取数据透视表格格式的表格的查询:
with t1 as(
select station,avg([Average_Cycle_Time_I]) Avg_cycle_tm from [dbo].[V_FM_Cycle_Time] group by station )
,
t2 as(
SELECT distinct *
FROM (SELECT [Station],[Rake_Type_Name],Datename(Month,[Month]) as [Month name],
[Average_Cycle_Time_I]
FROM [dbo].[V_FM_Cycle_Time]
GROUP BY [Station],[Rake_Type_Name],Datename(Month,[Month]),
[Average_Cycle_Time_I]) AS MonthlyData
PIVOT(avg([Average_Cycle_Time_I])
FOR [Month Name] IN ([April],[May],
[June],[July],[August],[September],[October],[November],
[December],[January],[February],[March]
)) AS MonthPivot)
select t2.*,t1.Avg_cycle_tm from t1, t2 where t1.Station=t2.Station
需要帮助。 提前致谢 钱达纳