再问按时间查询问题!
表的形式为
id starttm
1 2003-07-15 11:27:53
2 2003-07-15 11:27:53
3 2003-07-15 11:27:53
4 2003-07-15 11:27:54
5 2003-07-15 11:27:55
6 2003-07-15 11:27:56
7 2003-07-15 11:27:56
8 2003-07-15 11:27:57
...........................
需要按时间进行抽样统计,譬如抽样时间间隔为3秒,统计结果为
tm count1
2003-07-15 11:27:53 3
2003-07-15 11:27:56 2
.............................
该sql语句实现为
select starttm tm, count(*) countl from table1
where datediff(ss, (select min(startm) from table1), starttm) % 3 = 0
group by starttm
如果在抽样时刻没有记录,如何让他显示为0?
即若在2003-07-15 11:27:59时刻没有记录,统计结果为:
tm count1
2003-07-15 11:27:53 3
2003-07-15 11:27:56 2
2003-07-15 11:27:59 0
.............................
thanks