我有一张表格,列出了在sqlite3数据库中玩过的游戏列表。"datetime"字段是游戏结束的日期时间字段。"duration"字段是游戏持续时间的秒数。我想知道过去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
有没有一种方法可以动态地创建这个日期表?或者我可以得到一个类似于这样的效果,而不必实际创建一个新表,只需创建本周所有秒数的列表即可?
谢谢。
select number from numbers limit 100;
它只是一个方便的结构... - cethegeek