If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > getting counts for each hour of a day

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-07-04, 17:46
manth manth is offline
Registered User
 
Join Date: Mar 2004
Posts: 54
getting counts for each hour of a day

Hi,

I have a table called MQMD
which has the following columns
TSTAMP
MSGID
PUTDATE
PUTTIME ...e.t.c

I want out put as follows

Time range Message Count
--------------- ------------------
00:00 - 00:59 1000
01:00 - 01:59 2000
02:00 - 02:59 349
....
....
till the messages are available in the day

Is it possible to achieve this result using SQL?

I appreciate your help!!

Thanks
Reply With Quote
  #2 (permalink)  
Old 04-07-04, 20:52
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Re: getting counts for each hour of a day

Quote:
Originally posted by manth
Hi,

I have a table called MQMD
which has the following columns
TSTAMP
MSGID
PUTDATE
PUTTIME ...e.t.c

I want out put as follows

Time range Message Count
--------------- ------------------
00:00 - 00:59 1000
01:00 - 01:59 2000
02:00 - 02:59 349
....
....
till the messages are available in the day

Is it possible to achieve this result using SQL?

I appreciate your help!!

Thanks
Assuming your range is based on TSTAMP:

select hour(tstamp), count(1) from mqmd where date(tstamp)=date(current timestamp) group by hour(tstamp);
Reply With Quote
  #3 (permalink)  
Old 04-08-04, 08:23
manth manth is offline
Registered User
 
Join Date: Mar 2004
Posts: 54
Excellent!!

It's working nice, But i have a question, the query has return me the following result

db2 => SELECT HOUR(TSTAMP), COUNT(MSGID) FROM DB2.MQMD WHERE DATE(TSTAMP)=DATE('2004-04-07-00.00.00') GROUP BY HOUR(TSTAMP)

1 2
----------- -----------
0 94
1 96
2 96
3 96
4 96
5 96
6 104
7 145
8 123

9 record(s) selected.

Does it mean that it has count from 00:00 - 08:59?

Please clarify this!

Thanks
Reply With Quote
  #4 (permalink)  
Old 04-08-04, 09:40
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Yes ...

Quote:
Originally posted by manth
Excellent!!

It's working nice, But i have a question, the query has return me the following result

db2 => SELECT HOUR(TSTAMP), COUNT(MSGID) FROM DB2.MQMD WHERE DATE(TSTAMP)=DATE('2004-04-07-00.00.00') GROUP BY HOUR(TSTAMP)

1 2
----------- -----------
0 94
1 96
2 96
3 96
4 96
5 96
6 104
7 145
8 123

9 record(s) selected.

Does it mean that it has count from 00:00 - 08:59?

Please clarify this!

Thanks
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #5 (permalink)  
Old 04-08-04, 10:06
manth manth is offline
Registered User
 
Join Date: Mar 2004
Posts: 54
Thumbs up

Excellent job!!
I appreciate it.

Thanks
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On