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

  • SEARCH
  • Home
  • 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 3842452
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:47:44+00:00 2026-05-19T15:47:44+00:00

Okay trying to construct a single query to save myself a whole bunch of

  • 0

Okay trying to construct a single query to save myself a whole bunch of time (rather than writing a ton of seperate queries), but I don’t even know how to start on this.

What I need to is look at single day and type and break out counts on actions, by hour, between 8:00am – 8:00pm. So for example I have the following fake table

TYPE_   ACTION_     TIMESTAMP_
------------------------------
A       processed   2010-11-19 10:00:00.000
A       processed   2010-11-19 10:46:45.000
A       processed   2010-11-19 11:46:45.000
A       processed   2010-11-19 12:46:45.000
A       processed   2010-11-19 12:48:45.000
A       pending     2010-11-19 11:46:45.000
A       pending     2010-11-19 11:50:45.000
A       pending     2010-11-19 12:46:45.000
A       pending     2010-11-19 12:48:45.000
B       pending     2010-11-19 19:48:45.000
B       pending     2010-11-19 21:46:45.000
.etc

So if I wanted to look at all records with

  • TYPE_ = ‘A’
  • on date 2010-11-19
  • grouped by ACTION_ per hour

I would see this result

ACTION_ NUMOCCURENCES   RANGE
---------------------------------------------
processed  2                10:00:00 - 11:00:00
pending    0                10:00:00 - 11:00:00
processed  1                11:00:00 - 12:00:00
pending    2                11:00:00 - 12:00:00
processed  2                12:00:00 - 13:00:00
pending    2                12:00:00 - 13:00:00

Or something similar to that, but that should at least give an idea of what I am looking for.

Can anyone help? Normally I would try to provide some sample code I’m working with, but I have no idea how I would work with the group by clauses needed to make this happen.

  • 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-19T15:47:45+00:00Added an answer on May 19, 2026 at 3:47 pm
    select
       action_,
       count(*) as numoccurences,
       to_char(timestamp_       , 'hh24') || ':00:00-' || 
       to_char(timestamp_ + 1/24, 'hh24') || ':00:00' as range
     from 
       tq84_action 
     where  
       timestamp_ between timestamp '2010-11-19 08:00:00' and 
                          timestamp '2010-11-19 20:00:00' and
       type_ = 'A'
     group by
       action_,
       to_char(timestamp_       , 'hh24') || ':00:00-' || 
       to_char(timestamp_ + 1/24, 'hh24') || ':00:00' 
     order by 
       range;
    

    Now, the above select statement only returns hours in which there is at least on action. In order to show a record for all hour – {processed/pending} combinations, the following amendments should be made to the query:

    select
       action_,
       count(type_) as numoccurences,
       to_char(timestamp_       , 'hh24') || ':00:00-' || 
       to_char(timestamp_ + 1/24, 'hh24') || ':00:00' as range_
     from (
       select * from tq84_action 
        where  
          timestamp_ between timestamp '2010-11-19 08:00:00' and 
                             timestamp '2010-11-19 20:00:00' and
          type_ = 'A'
        union all (
          select 
            null as type_,
            action.name_ as action_,
            date '2010-11-19' + 8/24 + hour.counter_ / 24 as timestamp_1
          from (
            select  
              level-1 counter_
            from dual
              connect by level <= 12
          ) hour,
          ( 
            select 'processed' as name_ from dual union all
            select 'pending'   as name_ from dual
          ) action
        )
     )
     group by
       action_,
       to_char(timestamp_       , 'hh24') || ':00:00-' || 
       to_char(timestamp_ + 1/24, 'hh24') || ':00:00' 
     order by 
       range_;
    

    BTW, here’s the DDL and DML I used:

    drop   table tq84_action;
    create table tq84_action (
      type_      varchar2( 1),
      action_    varchar2(10),
      timestamp_ timestamp
    );
    
    
    insert into tq84_action values('A', 'processed' , timestamp '2010-11-19 10:00:00.000');
    insert into tq84_action values('A', 'processed' , timestamp '2010-11-19 10:46:45.000');
    insert into tq84_action values('A', 'processed' , timestamp '2010-11-19 11:46:45.000');
    insert into tq84_action values('A', 'processed' , timestamp '2010-11-19 12:46:45.000');
    insert into tq84_action values('A', 'processed' , timestamp '2010-11-19 12:48:45.000');
    insert into tq84_action values('A', 'pending'   , timestamp '2010-11-19 11:46:45.000');
    insert into tq84_action values('A', 'pending'   , timestamp '2010-11-19 11:50:45.000');
    insert into tq84_action values('A', 'pending'   , timestamp '2010-11-19 12:46:45.000');
    insert into tq84_action values('A', 'pending'   , timestamp '2010-11-19 12:48:45.000');
    insert into tq84_action values('B', 'pending'   , timestamp '2010-11-19 19:48:45.000');
    insert into tq84_action values('B', 'pending'   , timestamp '2010-11-19 21:46:45.000');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so i'm trying to load up a bunch of profiles through C# and
Okay I have been trying to get this to work for some time now.
Okay so I'm trying to get my values rounded up to the nearest whole
Okay I'm trying to go for a more pythonic method of doing things. How
Okay I been trying to work this out but unable too. I have a
okay i have been trying to understand this for hours i am learning VB
Okay so I've been trying to position these 4 divs for about 6 hours
Okay so I'm trying to make a little gag program that will run away
Okay so what i am trying to achieve is use the youtube api to
OKay I don't use actionscript and trying to help my friend edit a flash

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.