我有一个查询,该查询返回给定机器生产运行期间发生的事件的时间戳之间的秒数。总结时间戳之间的经过时间SQL Server
我想获得在该持续时间内机器状态代码分组的时间总量。防爆。运行,计划外停机,计划停机。
我认为这涉及到我知道不允许的聚合的聚合。我相信是有办法做到这一点,虽然
SELECT
p1.productionRunId,
p1.statusCodeId,
DATEDIFF(SECOND, MAX(p2.startTime), p1.startTime) AS seconds
FROM
productionLog p1
INNER JOIN
wincc.dbo.productionLog p2 ON p1.productionRunId = p2.productionRunId
AND p2.startTime < p1.startTime
GROUP BY
p1.startTime, p1.productionRunId, p1.statusCodeId
Here is a picture of my current results with a description of what I would like.
从'group by'中删除'p.startTime'。 –