- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在寻找一个 SQL 查询来计算评论的平均时间(每月测量一次)。
我能够编写一个查询来测量原始帖子日期时间和评论日期时间之间的平均时间,但这仍然不正确,因为应该在当前评论和前一个评论之间测量时间,因为它们最相关的时间。
select
dateadd(month, datediff(month, 0, Comments.creationdate),0) [Date],
AVG(CAST(DATEDIFF(hour, Posts.CreationDate, Comments.creationdate ) AS BigInt)) [DelayHours]
from comments
INNER JOIN posts ON Comments.PostId = Posts.Id
GROUP BY
dateadd(month, datediff(month, 0, Comments.creationdate),0)
ORDER BY Date
最佳答案
我认为这样的事情应该可行。抱歉,暂时无法测试;如果我打印有误,我深表歉意。
WITH cte1 AS
(
SELECT c.PostId, c.creationdate,
ROW_NUMBER() OVER (PARTITION BY c.PostId ORDER BY c.creationdate) AS rn
FROM comments c
)
SELECT dateadd(month, datediff(month, 0, a.creationdate),0) [Date],
AVG(diff_hr) AS avg_diff
FROM
(
SELECT a1.PostId, a1.creationdate,
CASE
WHEN a1.rn = 1 THEN
CAST(DATEDIFF(hour,p.creationdate,a1.creationdate) AS BIGINT)
ELSE
CAST(DATEDIFF(hour,a2.creationdate,a1.creationdate) AS BIGINT)
END AS diff_hr
FROM cte1 a1
INNER JOIN posts p ON (p.Id = a1.PostId)
LEFT JOIN cte1 a2 ON (a2.PostId = a1.PostId AND a2.rn = a1.rn-1)
)a
GROUP BY dateadd(month, datediff(month, 0, a.creationdate),0)
更新对于 SQLServer 2012 LAG
将简化解决方案...我注意到有关版本太晚的评论。
更新 2 打印错误已修复(遗漏 FROM
子句和 p.PostId
更改为 p.Id
以匹配表定义)
关于sql - 如何使用 SQL 计算在 stackexchange 上发表评论所需的平均时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14415647/
直到今天,我一直在使用以下内容连接到 Redis,没有问题,现在我必须明确说明提供数据库参数,因为: ArgumentOutOfRangeException Specified argument wa
Microsoft.AspNet.SignalR.Redis 和 StackExchange.Redis.Extensions.Core 在同一个项目中使用。前者需要StackExchange.Red
我对如何在 StackExchange.Redis 中使用 Queue 感到困惑。 我试过下载源代码并查看文档。 我仍然找不到如何使用它。 请给我建议。 非常感谢。 最佳答案 Redis 通过 LPU
有没有办法使用stackexchange.redis删除redis中的所有键? 我正在尝试在我的单元测试设置中刷新我的 redis 数据库。 谢谢。 最佳答案 基本上,它在IServer . 有关原因
如何使用 StackExchange.Redis 指定 Redis 服务器的密码?我猜你将它添加到传递给 Connect 方法的配置字符串中。我似乎无法找到需要指定的格式。 最佳答案 我会将键/值对的
当我关注 Azure documentation 时关于如何在Azure Portal中使用Redis缓存,我注意到了这个注释: If you prefer to use a strong-named
使用 the StackExchange API ,有可能找到很多关于用户的信息: { "badge_counts": { "bronze": 3, "silver": 2,
在我们的 webapi 代码中,我们使用 SignalR 和 redis 背板。我看到我们的代码在一段时间后挂起的问题。 StackExchange.Redis.StrongName.dll!Stac
我试图通过可用的 Nuget 包设置 RedisSessionProvider 以与我的 Azure 网站一起使用。 当我运行我的网站时,出现以下错误: Could not load type 'St
StackExchange.Redis 是一个高性能的 Redis 客户端库,主要用于 .NET 环境下与 Redis 服务器进行通信,大名鼎鼎的stackoverflow 网站就使用它。它使用
我正在建立一个网站,该网站对IT问题进行了分类。 如何获取stackoverflow上使用的所有标签的内容? 我需要对相同的内容使用相同的标记功能,但要分开使用。 如何提取所有标签的内容? (应该是几
我试图找到一些遵循某种模式的 key ,但我需要所有相关的 key ,而不仅仅是特定服务器中的 key 。 到目前为止,我一直在尝试使用文档示例访问特定服务器,但它不起作用。 var
我想在我的网站上添加一个页面,其布局带有动画面板,这些面板会根据点击的面板自动滑动,如 Stackexchange 的站点页面: https://stackexchange.com/sites Sta
这是使用 stackexchange.redis v1.1.603,.net 4.6,控制台应用程序。这是我的代码: using System; using System.Collections.Ge
我必须使用 stackexhange.redis C# 在 redis 缓存中频繁添加 N 个(独立)项目,每个项目具有不同的过期时间,以便客户端的时间最短,服务器端的阻塞和成本最小。 Redis 服
如果我理解正确的话,当调用像GET abc{def}ghi这样的东西时,Redis客户端会计算def的散列值,将它乘以16384然后直接发送请求到负责处理该特定空间部分的集群节点。 我想知道,如果 L
我最近将我的项目转移到 Redis session 。 Redis session 从登录到到达仪表板都可以完美运行。在此期间, session 的读写工作正常。但是,当我继续访问任何内页时,出现超时
想法是使用更少的连接和更好的性能。连接是否随时过期? 另外一个问题,_redis.GetDatabase()是否打开新连接? private static ConnectionMultiplexer
我正在尝试使用两个著名的 C# 驱动程序来评估 Redis ServiceStack和 StackExchange .不幸的是,我不能使用 ServiceStack,因为它不是免费的。现在我正在尝试
StackExchange.Redis 似乎是一个流行的 Redis C# 客户端。我不清楚 StackExchange.Redis 是否使用多级缓存? 也就是说,如果我从 Asp.net WebSi
我是一名优秀的程序员,十分优秀!