Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: SQL Query: Counting records by Time Interval
<fitzjarrell_at_cox.net> wrote in message
news:1182793426.358633.167900_at_n60g2000hse.googlegroups.com...
> On Jun 25, 11:27 am, "Chris Colclough" > <chris.colclough_at_no_spam.jhuapl.edu> wrote:
> > Which will not return the proper results as it groups by the hour and > crosses date boundaries to do so. > > > David Fitzjarrell >
Should get proper results. See the following test:
SQL> create table a (mts timestamp);
Table created.
SQL> insert into a values (systimestamp-1);
1 row created.
SQL> insert into a values (systimestamp);
1 row created.
SQL> insert into a values (systimestamp+1);
1 row created.
SQL> commit;
Commit complete.
SQL> alter session set nls_date_format='yyyy/mm/dd hh24:mi:ss';
Session altered.
SQL> select mts from a;
MTS
24-JUN-07 01.53.48.000000 PM 25-JUN-07 01.53.53.556143 PM 26-JUN-07 01.53.57.000000 PM
SQL> select trunc(mts, 'hh24') from a;
TRUNC(MTS,'HH24')
2007/06/24 13:00:00 2007/06/25 13:00:00 2007/06/26 13:00:00
The trunc(mts, 'hh24') does return the hour within the specified timestamp value. Received on Mon Jun 25 2007 - 12:58:35 CDT
![]() |
![]() |