Idmpc
Programmer
- Jun 25, 2008
- 16
Hi everyone
I'm using MS Access
I have a table that has a field called "DT" of DateTime type, between others.
there's at least 3 or 4 records for each second, for example:
No. Record Field1 DT
1 AA 06/25/2008 15:10:01
2 BB 06/25/2008 15:10:01
3 CC 06/25/2008 15:10:01
4 DD 06/25/2008 15:10:01
5 EE 06/25/2008 15:10:02
6 FF 06/25/2008 15:10:02
7 GG 06/25/2008 15:10:02
8 HH 06/25/2008 15:10:03
9 JJ 06/25/2008 15:10:03
etc..
and the records go from 00:00:00 to 23:59:59 for about 7 days. (I have about 1.200.000+ records on the database)
What I want to do is to make a SQL Query that will organize these DateTime values in hour ranges. I want my SQL Query result to be the following:
Range Count
00:00:00 - 01:00:00 789
01:00:01 - 02:00:00 98
02:00:01 - 03:00:00 978
... ...
23:00:00 - 23:59:59 56
I want the "Count" field to show how many records are contained inside the range.
Please do note that, at first, I do not care about the dates, only the hours stored on the database, since I want to know the number of records inside those ranges, date independent. However, it would be nice if you could also show me how to count how many records are inside that range within a specified date.
I know that if I use the command Format (DT, "hh:nn:ss") I will retrieve only the Time part of the DateTime "DT" Field, but I have no idea of how to organize the counts in those ranges I need.
I've tried to create a new, temporary table to store the ranges and use JOIN somehow, but I'm not that much of an expert on SQL and I could get no results.
Can anyone help me?
Thanks in advance.
I'm using MS Access
I have a table that has a field called "DT" of DateTime type, between others.
there's at least 3 or 4 records for each second, for example:
No. Record Field1 DT
1 AA 06/25/2008 15:10:01
2 BB 06/25/2008 15:10:01
3 CC 06/25/2008 15:10:01
4 DD 06/25/2008 15:10:01
5 EE 06/25/2008 15:10:02
6 FF 06/25/2008 15:10:02
7 GG 06/25/2008 15:10:02
8 HH 06/25/2008 15:10:03
9 JJ 06/25/2008 15:10:03
etc..
and the records go from 00:00:00 to 23:59:59 for about 7 days. (I have about 1.200.000+ records on the database)
What I want to do is to make a SQL Query that will organize these DateTime values in hour ranges. I want my SQL Query result to be the following:
Range Count
00:00:00 - 01:00:00 789
01:00:01 - 02:00:00 98
02:00:01 - 03:00:00 978
... ...
23:00:00 - 23:59:59 56
I want the "Count" field to show how many records are contained inside the range.
Please do note that, at first, I do not care about the dates, only the hours stored on the database, since I want to know the number of records inside those ranges, date independent. However, it would be nice if you could also show me how to count how many records are inside that range within a specified date.
I know that if I use the command Format (DT, "hh:nn:ss") I will retrieve only the Time part of the DateTime "DT" Field, but I have no idea of how to organize the counts in those ranges I need.
I've tried to create a new, temporary table to store the ranges and use JOIN somehow, but I'm not that much of an expert on SQL and I could get no results.
Can anyone help me?
Thanks in advance.