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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:44:22+00:00 2026-06-11T06:44:22+00:00

I have a query that, when executed, returns all hours for the past 24

  • 0

I have a query that, when executed, returns all hours for the past 24 hours. So if you run the query at 10:55am the results will be from 11am yesterday up to 10am today.

Here is the query I am using:

select to_char(trunc(a_date,'HH24'),'HH24') col_x,
       type_name seriesname,
       sum(a_measure_3) col_y
from a_agg,
     (select trunc(sysdate, 'hh')-1 POS from dual)
where a_date >= POS
and   a_date <= POS + 1
group by trunc(a_date,'HH24'),
         type_name 
order by 2;

And this is the output that I am looking for:

COL_X  | SERIESNAME  | COL_Y
-----------------------------------
 11    |  STATUS1    |  6715846
 12    |  STATUS1    |  7064692
 13    |  STATUS1    |  6821742
 14    |  STATUS1    |  6241758
 15    |  STATUS1    |  6364713
 16    |  STATUS1    |  6762539
 17    |  STATUS1    |  6200213
 18    |  STATUS1    |  8479341
 19    |  STATUS1    |  13346516
 20    |  STATUS1    |  10107274
 21    |  STATUS1    |  3716290
 22    |  STATUS1    |  1321966
 23    |  STATUS1    |  433947
 00    |  STATUS1    |  200273
 01    |  STATUS1    |  97429
 02    |  STATUS1    |  81726
 03    |  STATUS1    |  124943
 04    |  STATUS1    |  284946
 05    |  STATUS1    |  1360847
 06    |  STATUS1    |  4250001
 07    |  STATUS1    |  5840156
 08    |  STATUS1    |  6666608
 09    |  STATUS1    |  6949196
 10    |  STATUS1    |  982411

Now my question is, is there a way to order by COL_X to get this specific output, as my current order by 2 wont always return the above result.

  • 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-11T06:44:24+00:00Added an answer on June 11, 2026 at 6:44 am

    I think you are wanting to order by the actual date column (a_date).
    It won’t allow you to order by it on its own as it is not used in the group by. To allow it, you need to aggregate the date somehow. Simply using a MAX or MIN could work.

    So in short, just ORDER BY MAX(a_date)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that might be executed by several users consecutively. I'm scared
I have a complex query that gets executed like this: if ($stmt = $dbi->prepare($pt_query))
I am using in C# MYsql .I have query that works if I run
I have a query that successfully grabs the unique products from my products table
I have a page that has to render a huge set of query results
When I run a query which returns millions of rows from within Sql Management
I have code that runs a query on the database and returns some data
I have a web service written in PHP, that returns JSON results. It works
I have the following query that executes perfectly in MySQL, but it is giving
I have a query that I need to execute that I do not know

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.