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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:43:24+00:00 2026-06-01T05:43:24+00:00

I would like to rank sequential rows with the null value inside a group

  • 0

I would like to rank sequential rows with the null value inside a group of the same natural key. The database is oracle.

Here’s the example :

NAT_KEY      ATTRIBUTE_A        ORDERED_FIELD               RANK
     A                A                     1
     A                                      2                  1
     A                A                     4
     A                I                     6
     A                                      8                  1
     A                                      10                 2
     A                                      11                 3
     B                                      2                  1
     B                                      3                  2
     B                A                     5
     B                A                     6
     B                                      9                  1
     C                A                     1
     C                A                     5
     C                I                     6
     C                                      7                  1
     C                                      8                  2

There must be a way with row_number() function, level and connect by or another one.

  • 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-01T05:43:25+00:00Added an answer on June 1, 2026 at 5:43 am

    I finally figured it out with Andriy M’s link.
    Here’s the solution :

    select grouped_table.nat_key, 
           grouped_table.attr, 
           grouped_table.order_by,  
           case 
             when attr is null 
               then row_number() over (partition by nat_key, attr, grp order by order_by) 
             else null
           end rowrank 
    from (
      select the_table.*, 
             row_number() over (partition by nat_key order by order_by) - row_number() over (partition by nat_key, nvl2(attr, 1, 0) order by order_by) grp 
      from (
        select 'A' nat_key, 'A' attr, 1 order_by from dual 
        union all 
        select 'A' nat_key, null attr, 2 order_by from dual 
        union all 
        select 'A' nat_key, 'A' attr, 4 order_by from dual 
        union all 
        select 'A' nat_key, 'I' attr, 6 order_by from dual 
        union all 
        select 'A' nat_key, null attr, 8 order_by from dual 
        union all 
        select 'A' nat_key, null attr, 10 order_by from dual 
        union all 
        select 'A' nat_key, null attr, 11 order_by from dual 
        union all 
        select 'B' nat_key, null attr, 2 order_by from dual 
        union all 
        select 'B' nat_key, null attr, 3 order_by from dual 
        union all 
        select 'B' nat_key, 'A' attr, 5 order_by from dual 
        union all 
        select 'B' nat_key, 'A' attr, 6 order_by from dual 
        union all 
        select 'B' nat_key, null attr, 9 order_by from dual 
        union all 
        select 'C' nat_key, 'A' attr, 1 order_by from dual 
        union all 
        select 'C' nat_key, 'A' attr, 5 order_by from dual 
        union all 
        select 'C' nat_key, 'I' attr, 6 order_by from dual 
        union all 
        select 'C' nat_key, null attr, 7 order_by from dual 
        union all 
        select 'C' nat_key, null attr, 8 order_by from dual 
      ) the_table 
    ) grouped_table 
    order by nat_key, order_by
    

    Thanks!

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

Sidebar

Related Questions

I would like to know if there is any easy way to rank blog
Problem Statement: I would like to create an offline database to lookup prices/info on
I am developing in Rails an app where I would like to rank a
Suppose I have 2 tables, query and rank. I would like to know if
I'm doing some statistics based on a database of states. I would like to
I would like to know how to create a default value. For example: CREATE
I would like to rank or sort a collection of items (with size potentially
Would like to get a list of advantages and disadvantages of using Stored Procedures.
Would like to create a strong password in C++. Any suggestions? I assume it
Would like to be able to set colors of headings and such, different font

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.