SQL 审核日志运行总计
我有一个带有审核日志的表:
BugId Timestamp Status
1 2010-06-24 10:00:00 open
2 2010-06-24 11:00:00 open
1 2010-06-25 12:00:00 closed
2 2010-06-26 13:00:00 closed
我想要打开和关闭的错误的运行总数,例如:
Timestamp # Status
2010-06-25 00:00:00 2 open
2010-06-26 00:00:00 1 open
2010-06-26 00:00:00 1 closed
2010-06-27 00:00:00 2 closed
如何在 Microsoft SQL Server 2000 中执行此查询(或类似查询)?
输出旨在用于提供时间序列图表,因此我不关心是否有输出为 0 的行,因为我可能只会选择像上个月这样的时间跨度。
I have a table with an audit log:
BugId Timestamp Status
1 2010-06-24 10:00:00 open
2 2010-06-24 11:00:00 open
1 2010-06-25 12:00:00 closed
2 2010-06-26 13:00:00 closed
I want a running total of open and closed bugs like:
Timestamp # Status
2010-06-25 00:00:00 2 open
2010-06-26 00:00:00 1 open
2010-06-26 00:00:00 1 closed
2010-06-27 00:00:00 2 closed
How may I do this query (or similar) in Microsoft SQL Server 2000?
The output is intended to be used to feed a time series chart so I do not care if there are rows with 0 output since I will probably only select a timespan like the last month.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为输出实际上与示例数据匹配:25 日(上午 12 点),有两个未解决的错误。 26 日,有 1 个开放 bug,1 个已关闭。到 27 日,所有 bug 都已修复。
目前尚不清楚应如何创建主要日期。对于我的示例,我预加载了我知道正确的日期,但这可以根据用户的要求以多种方式完成。
无论如何,代码如下。这对于同一天多次打开和关闭错误的情况应该有效。它的运行假设是不能同时打开和关闭 bug。
结果:
I think the output actually matches the sample data: on the 25th (12am), there are two open bugs. On the 26th, there is one open bug and one closed. And by the 27th, all bugs are closed.
It isn't clear how the main dates should be created. For my example, I pre-loaded the dates that I knew to be right but this could be accomplished in a variety of ways depending on the requirements of the user.
Anyway, the code is below. This should work for instances where a bug is opened and closed multiple times on the same day. It operates under the assumption that a bug cannot be opened and closed at the same time.
Results: