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 7977621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:15:16+00:00 2026-06-04T09:15:16+00:00

I need a SINGLE query that does this sequence in oracle. select count(*) from

  • 0

I need a SINGLE query that does this sequence in oracle.

select count(*) from table1
where request_time < timestamp'2012-05-19 12:00:00' and (end_time > timestamp'2012-05-19 12:00:00' or end_time=null);

select count(*) from table1
where request_time < timestamp'2012-05-19 13:00:00' and (end_time > timestamp'2012-05-19 13:00:00' or end_time=null);

select count(*) from table1
where request_time < timestamp'2012-05-19 14:00:00' and (end_time > timestamp'2012-05-19 14:00:00' or end_time=null);

select count(*) table1
where request_time < timestamp'2012-05-19 15:00:00' and (end_time > timestamp'2012-05-19 15:00:00' or end_time=null);

select count(*) from table1
where request_time < timestamp'2012-05-19 16:00:00' and (end_time > timestamp'2012-05-19 16:00:00' or end_time=null);

As you see the hour is increasing one by one.
here is the output

COUNT(*)               
1085                   

COUNT(*)               
1233                   

COUNT(*)               
1407                   

COUNT(*)               
1322                   

COUNT(*)               
1237

I have written a query but it does not give me the right answer!

select col1, count(*) from
(select TO_CHAR(request_time, 'YYYY-MM-DD HH24') as col1 from table1
 where request_time <= timestamp'2012-05-19 12:00:00' and (end_time >= timestamp'2012-05-19 12:00:00' or end_time=null))
group by col1 order by col1;

this query gives me a result set that sum of it’s count(*) is equal to the first query written above!
here is the result:

COL1          COUNT(*)               
------------- ---------------------- 
2012-05-19 07      22                     
2012-05-19 08      141                    
2012-05-19 09      322                    
2012-05-19 10      318                    
2012-05-19 11      282  
  • 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-06-04T09:15:17+00:00Added an answer on June 4, 2026 at 9:15 am

    Note the usage of trunc expression with date values. You can omit the alter session if you are not running the query in sql*plus.

    SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
    
    Session altered.
    
    SQL> SELECT 
           trunc(created,'HH'), 
           count(*) 
         FROM 
           test_table 
         WHERE 
           created > trunc(SYSDATE -2) 
         group by trunc(created,'HH');
    
    
    TRUNC(CREATED,'HH')   COUNT(*)
    ------------------- ----------
    2012-05-21 09:00:00        748
    2012-05-21 16:00:00         24
    2012-05-21 17:00:00         12
    2012-05-21 22:00:00        737
    2012-05-21 23:00:00        182
    2012-05-22 20:00:00         16
    2012-05-22 21:00:00        293
    2012-05-22 22:00:00        610
    
    8 ROWS selected.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to do a LINQ2DataSet query that does a join on more than
I need single-producer, single-consumer FIFO query because I need to process messages in the
I need to Justify single line text and I had this issue in past
I need to create a single trace file that spans several days for one
I need to develop a single routine that will be fired each 5 minutes
I want to build a single select stored procedure for SQL 2005 that is
Hi I need help to understand the decode part of a query that goes
I am trying to create a single query for getting information from the main
I have a long running query that returns a large data set. This query
i need single file wsdl, how to build single file wsdl? Thanks.

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.