Results 1 to 3 of 3

Thread: group by hour

  1. #1
    Join Date
    Aug 2005
    Location
    Kuala Lumpur, MY
    Posts
    108

    Unanswered: group by hour

    hie
    i have a table where the reload_date contains date in this format
    2/2/2006 6:06:22 PM 10.00
    2/2/2006 6:06:24 PM 10.00


    i would like to select a certain field and group it by hourly basis.. what is the best way ?

    for ex:
    2/2/2006 12:00:00 AM(should count all the amount from 12:00:00 AM - 12:00:59 AM)
    2/2/2006 01:00:00 AM
    .
    .
    .

    Any idea ?

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Something like this:
    Code:
    SELECT 
      TO_CHAR(date_column, 'dd.mm.yyyy hh24') time_value, 
      SUM(amount) sum_amount
    FROM some_table
    GROUP BY TO_CHAR(date_column, 'dd.mm.yyyy hh24');
    Adjust time format according to your needs.

  3. #3
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    Try the following

    Code:
    SELECT 
      TO_CHAR(trunc(date_column,'hh'), 'dd.mm.yyyy hh24') time_value, 
      SUM(amount) sum_amount
    FROM some_table
    GROUP BY trunc(date_column,'hh');
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •