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 > Data Access, Manipulation & Batch Languages > ANSI SQL > Query Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-16-02, 00:03
seilsz seilsz is offline
Registered User
 
Join Date: Dec 2002
Posts: 3
Query Help

I am trying to aggregate some values from a table, and need some assistance.

I write a numeric value to the table once every hour of every day. The table contains data for an entire month. There is also a date field (DATETIME) that stores the record insert time. I would like to come up with a monthly average per hour. For example, I would like to average the sample from every day at 1AM.

I'm having trouble just using the hour from the DATETIME field, and I also don't know if I should be trying this with the GROUP BY function, or with some type of nestd query. Any help you can provide is greatly appreciated.

Thanks -
Reply With Quote
  #2 (permalink)  
Old 12-16-02, 03:59
alligatorsql.com alligatorsql.com is offline
Registered User
 
Join Date: Jul 2001
Location: Germany
Posts: 189
Question Which database do you use ?

Hello,

can you please give us a hint, which databases you using ?
In Oracle you can convert a date value with extracting the hout part by
using TO_CHAR(date_field, 'HH') or TO_CHAR(date_field, HH24) for numeric conversion.

Hope that helps ?

Manfred Peter
(Alligator COmpany GmbH)
http://www.alligatorsql.com
Reply With Quote
  #3 (permalink)  
Old 12-16-02, 09:05
seilsz seilsz is offline
Registered User
 
Join Date: Dec 2002
Posts: 3
My apologies ... the database is Oracle.
Reply With Quote
  #4 (permalink)  
Old 12-16-02, 09:10
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Quote:
Originally posted by seilsz
My apologies ... the database is Oracle.
So your query will be something like:

SELECT TO_CHAR(created_date,'HH24') hour, AVG( value )
FROM table
WHERE ...
GROUP BY TO_CHAR(created_date,'HH24');
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #5 (permalink)  
Old 12-16-02, 17:59
seilsz seilsz is offline
Registered User
 
Join Date: Dec 2002
Posts: 3
So simple, yet so hard for a newbie. Thank you very much for your help. It is greatly appreciated.

-Zach
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