按时间间隔分组
我需要将我的表分组为 15 分钟的间隔。我可以这样做:
select dateadd(minute, datediff(minute, 0, ts) / 15 * 15, 0), sum (goodpieces)
from StationCount
Group by dateadd(minute, datediff(minute, 0, ts) / 15 * 15, 0)
但是为了在图表中显示返回的数据,我还需要插入没有任何数据且当前未出现在我的 select 语句中的间隔。我该如何插入这些?
I need to Group my Table into 15 minutes Intervals. I can do that with:
select dateadd(minute, datediff(minute, 0, ts) / 15 * 15, 0), sum (goodpieces)
from StationCount
Group by dateadd(minute, datediff(minute, 0, ts) / 15 * 15, 0)
But to display the returned data in a chart i need to insert also the intervals which don't have any data and aren't currently appearing in my select statement. How do i insert these?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个表,其中包含以 15 分钟为增量的每个可能的时间戳,然后从该表与上面的查询执行 LEFT JOIN。
如果您知道图表始终涵盖 24 小时时间段,则只需创建一个包含数字 0-95 的表格,然后对于每个条目将其添加到图表的开始时间。
Create a table with every possible timestamp in 15 minute increments, and do a LEFT JOIN from it to your query above.
If you know your chart always covers a 24 hour period, you only need to create a table with the numbers 0-95, then for each entry add it to the start time of your chart.
像这样的事情可能会对你有所帮助。
Something like this might help you.