表如下:
id 时间(到秒) 人数1 人数2 人数3
1 2011年9月28日11:18:18 10 15 20
2 2011年9月28日11:18:17 10 15 20
3 2011年9月28日11:18:16 10 15 20
4 2011年9月28日11:18:15 10 15 20
5 2011年9月28日11:18:14 10 15 20
6 2011年9月28日11:18:13 10 15 20
.
.
.
10 2011年9月28日11:17:18 10 15 20
11 2011年9月28日11:17:17 10 15 20要求:
按分钟查询出人数1 = 1分钟内人数/60
以此类推,
还有按小时,和按天来算出人数急急急
id 时间(到秒) 人数1 人数2 人数3
1 2011年9月28日11:18:18 10 15 20
2 2011年9月28日11:18:17 10 15 20
3 2011年9月28日11:18:16 10 15 20
4 2011年9月28日11:18:15 10 15 20
5 2011年9月28日11:18:14 10 15 20
6 2011年9月28日11:18:13 10 15 20
.
.
.
10 2011年9月28日11:17:18 10 15 20
11 2011年9月28日11:17:17 10 15 20要求:
按分钟查询出人数1 = 1分钟内人数/60
以此类推,
还有按小时,和按天来算出人数急急急
set @d2=(select MAX(时间)from tb)
set @d1=DATEADD(d,-1,getdate())
while(@d1<@d2)
begin
select @d1,(select 人数1 from Tb where 时间 =(select MAX(时间) from Tb where 时间=@d1 or 时间<@d1))
,(select 人数2 from Tb where 时间 =(select MAX(时间) from Tb where 时间=@d1 or 时间<@d1))
,(select 人数3 from Tb where 时间 =(select MAX(时间) from Tb where 时间=@d1 or 时间<@d1))
set @d1=DATEADD(MINUTE,1,@d1)
end
from tb
group by date(时间)
from tb
group by SECOND(时间)select MINUTE(时间),sum(人数1),sum(人数2),sum(人数3),sum(人数1)+sum(人数2)+sum(人数3)
from tb
group by MINUTE(时间)
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。