您好我之前已经问过这个问题,但可能会说得对 希望有人能帮助我
我正在尝试获取一个SQLite查询来计算Rolling TimeFrame中值的出现并返回一个不同的计数
我的数据看起来像这样
--------- ---------- DATA
TimeStamp UserName 2015-01-12 06:07:00 JamesG 2015-01-12 06:07:00 JohnH 2015-01-12 06:10:00 JohnH 2015-01-12 06:10:00 James 2015-01-12 06:10:00 Dean 2015-01-12 06:10:00 Alicia 2015-01-12 06:12:00 Ann 2015-01-12 06:12:00 Dean 2015-01-12 06:12:00 JohnH
这是我想要的结果
Result count "2015-01-12 06:07:00" 2 "2015-01-12 06:10:00" 4 "2015-01-12 06:12:00" 3
使用我当前的选择我得到一个结果,但它不考虑时间戳,它产生5分钟间隔
WITH RECURSIVE min_time(t) AS ( SELECT datetime((strftime('%s', (SELECT MIN(TimeStamp) FROM ConcurrentUsers) ) / 300) * 300, 'unixepoch') ), max_time(t) AS ( SELECT datetime((strftime('%s', (SELECT MAX(TimeStamp) FROM ConcurrentUsers) ) / 300) * 300, 'unixepoch') ), intervals(t) AS ( SELECT t FROM min_time UNION ALL SELECT datetime(t, '+5 minutes') FROM intervals WHERE t <= (SELECT t FROM max_time) ) SELECT t AS interval, (SELECT COUNT(Distinct(strftime('%M',TimeStamp))) FROM ConcurrentUsers WHERE TimeStamp < datetime(intervals.t, '+5 minutes') AND TimeStamp >= intervals.t AS Count FROM intervals where interval >= date('now') ORDER BY date(interval) DESC
任何帮助将不胜感激。
我想我找到了解决方案
WITH C AS (SELECT DISTINCT TimeStamp FROM ConcurrentUsers) SELECT Count(Distinct(UserName))TheCount,TimeStamp FROM ConcurrentUsers where TimeStamp >= date('now') Group by TimeStamp ORDER BY date(TimeStamp) DESC