Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5981049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:53:19+00:00 2026-05-22T21:53:19+00:00

I have an events table with two columns eventkey (unique, primary-key) and createtime ,

  • 0

I have an events table with two columns eventkey (unique, primary-key) and createtime, which stores the creation time of the event as the number of milliseconds since Jan 1 1970 in a NUMBER column.

I would like to create a “histogram” or frequency distribution that shows me how many events were created in each hour of the past week.

Is this the best way to write such a query in Oracle, using the width_bucket() function? Is it possible to derive the number of rows that fall into each bucket using one of the other Oracle analytic functions rather than using width_bucket to determine what bucket number each row belongs to and doing a count(*) over that?

-- 1305504000000 = 5/16/2011 12:00am GMT
-- 1306108800000 = 5/23/2011 12:00am GMT
select 
timestamp '1970-01-01 00:00:00' + numtodsinterval((1305504000000/1000 + (bucket * 60 * 60)), 'second') period_start,
numevents
from (
  select bucket, count(*) as events from (
    select eventkey, createtime, 
    width_bucket(createtime, 1305504000000, 1306108800000, 24 * 7) bucket
    from events 
    where createtime between 1305504000000 and 1306108800000
  ) group by bucket
) 
order by period_start
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:53:20+00:00Added an answer on May 22, 2026 at 9:53 pm

    If your createtime were a date column, this would be trivial:

    SELECT TO_CHAR(CREATE_TIME, 'DAY:HH24'), COUNT(*) 
      FROM EVENTS
     GROUP BY TO_CHAR(CREATE_TIME, 'DAY:HH24');
    

    As it is, casting the createtime column isn’t too hard:

    select TO_CHAR( 
             TO_DATE('19700101', 'YYYYMMDD') + createtime / 86400000), 
             'DAY:HH24') AS BUCKET, COUNT(*)
       FROM EVENTS
      WHERE createtime between 1305504000000 and 1306108800000
     group by TO_CHAR( 
             TO_DATE('19700101', 'YYYYMMDD') + createtime / 86400000), 
             'DAY:HH24') 
     order by 1
    

    If, alternatively, you’re looking for the fencepost values (for example, where do I go from the first decile (0-10%) to the next (11-20%), you’d do something like:

    select min(createtime) over (partition by decile) as decile_start,
           max(createtime) over (partition by decile) as decile_end,
           decile
      from (select createtime, 
                   ntile (10) over (order by createtime asc) as decile
              from events
             where createtime between 1305504000000 and 1306108800000
           )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which contains chronological events. They have a type, time and
I have a table which contains chronological events. They have a type, time and
I have a table of events with a recorded start and end time as
I have an Oracle table which contains event log messages for an application. We
I have an Events table whose goal is to store actions done by web
I have a table of events, I need to find all tail events of
I have several log files of events (one event per line). The logs can
Suppose you have the tables Presentations and Events . When a presentation is saved
I have 2 tables event + event_artist event eventId | eventName ------------------- 1 ,
For my Django app I have Events, Ratings, and Users. Ratings are related to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.