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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:25:25+00:00 2026-06-07T07:25:25+00:00

I am having some issues with ranking some columns in Oracle. I have two

  • 0

I am having some issues with ranking some columns in Oracle. I have two columns I need to rank–a group id and a date.

I want to group the table two ways:

  1. Rank the records in each GROUP_ID by DATETIME (RANK_1)
  2. Rank the GROUP_IDs by their DATETIME, GROUP_ID (RANK_2)

It should look like this:

GROUP_ID  |    DATE    |   RANK_1  |  RANK_2
----------|------------|-----------|----------
    2     |  1/1/2012  |      1    |    1
    2     |  1/2/2012  |      2    |    1
    2     |  1/4/2012  |      3    |    1   
    3     |  1/1/2012  |      1    |    2
    1     |  1/3/2012  |      1    |    3

I have been able to do the former, but have been unable to figure out the latter.

SELECT   group_id,
         datetime,
         ROW_NUMBER() OVER (PARTITION BY group_id ORDER BY datetime) AS rn,
         DENSE_RANK() OVER (ORDER BY group_id) AS rn2
FROM     table_1
ORDER BY group_id;

This incorrectly orders the RANK_2 field:

GROUP_ID  |    DATE    |   RANK_1  |  RANK_2
----------|------------|-----------|----------
    1     |  1/3/2012  |     1     |    1
    2     |  1/1/2012  |     1     |    2
    2     |  1/2/2012  |     2     |    2
    2     |  1/4/2012  |     3     |    2
    3     |  1/1/2012  |     1     |    3
  • 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-07T07:25:28+00:00Added an answer on June 7, 2026 at 7:25 am

    Assuming you don’t have an actual id column in the table, it appears that you want to do the second rank by the earliest date in each group. This will require a nested subquery:

    select group_id,  datetime, rn,
           dense_rank() over (order by EarliestDate, group_id) as rn2
    from (SELECT group_id,  datetime, 
                 ROW_NUMBER() OVER (PARTITION BY group_id ORDER BY datetime) AS rn, 
                 min(datetime) OVER (partition by group_id) as EarliestDate
          FROM table_1
         ) t
    ORDER BY group_id; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having some issues getting this MPMoviePlayerViewController to work. I have two sample URLs pointing
having some issues with a networking assignment. End goal is to have a C
I have been having some issues retrieving JSON data from a WCF service application
Having some issues running my code local. I have host file setup like this:
Having some issues with C. I have this is my code: // First line
I'm having some issues returning unique results from a table that has some repeating
I am having some issues regarding inheritance. I have a class of Person, and
I'm having some issues with checkboxes in a table being overridden by the onClick
I am having some issues with special characters in Crystal Reports. I have some
We are having some issues getting SharePoint to work as we want it 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.