【发布时间】:2009-11-02 20:13:26
【问题描述】:
我有一个表格,其中列出了在 sqlite3 数据库中玩过的游戏。 “日期时间”字段是游戏结束的日期时间。 “持续时间”字段是游戏持续的秒数。我想知道在过去 24 小时中,至少有 5 场比赛同时运行的百分比。我计算出在给定时间运行的游戏数量:
select count(*)
from games
where strftime('%s',datetime)+0 >= 1257173442 and
strftime('%s',datetime)-duration <= 1257173442
如果我有一个简单的每秒(或每 30 秒或其他)列表的表格,我可以做一个像这样的有意识的笛卡尔积:
select count(*)
from (
select count(*) as concurrent, d.second
from games g, date d
where strftime('%s',datetime)+0 >= d.second and
strftime('%s',datetime)-duration <= d.second and
d.second >= strftime('%s','now') - 24*60*60 and
d.second <= strftime('%s','now')
group by d.second) x
where concurrent >=5
有没有办法即时创建此日期表?或者我可以得到与此类似的效果,而无需实际创建一个新表,它只是本周所有秒数的列表?
谢谢
【问题讨论】: