就可视化而言,我知道这不是您正在谈论的定期采样,但我会查看用户的所有行并选择一个间隔桶,桶内的 SUM 并显示在条形图或类似物中。这将显示一个真正的“分布”,因为在一个时间范围内的许多事件可能很重要。
SELECT DATEADD(day, DATEDIFF(day, 0, timefield), 0) AS bucket -- choose an appropriate granularity (days used here)
,COUNT(*)
FROM entries
WHERE uid = ?
GROUP BY DATEADD(day, DATEDIFF(day, 0, timefield), 0)
ORDER BY DATEADD(day, DATEDIFF(day, 0, timefield), 0)
或者,如果您不喜欢必须重复自己的方式 - 或者如果您正在使用不同的存储桶并希望在 3-D 中分析许多用户(在 Z 中测量 x、y uid、存储桶):
SELECT uid
,bucket
,COUNT(*) AS measure
FROM (
SELECT uid
,DATEADD(day, DATEDIFF(day, 0, timefield), 0) AS bucket
FROM entries
) AS buckets
GROUP BY uid
,bucket
ORDER BY uid
,bucket
如果我想以 3-D 绘图,我可能会根据一些对用户有意义的整体指标来确定一种对用户进行排序的方法。