Conditional ROW_NUMBER() to skip nulls still counting them











up vote
0
down vote

favorite












I am trying to add a ROW_NUMBER column to a data set that follows the order of [Withdrawal then Fee; Withdrawal then Fee] based upon whether the column NETWORKCD is null. However, my row_number formula is still counting Nulls even though it's not displaying the numbers, like so:



+--------+-------------+------------+-----------+-------------+
| Acctid | Transaction | PostDate | NetworkCd | PeriodCount |
+--------+-------------+------------+-----------+-------------+
| 12345 | Withdrawal | 10/4/2018 | FRGN | 1 |
| 12345 | Fee | 10/4/2018 | | |
| 12345 | Withdrawal | 10/11/2018 | FRGN | 3 |
| 12345 | Fee | 10/11/2018 | | |
| 12345 | Withdrawal | 10/22/2018 | FRGN | 5 |
| 12345 | Fee | 10/22/2018 | | |
+--------+-------------+------------+-----------+-------------+


I am using the following formula for PeriodCount



(case when networkcd is not null 
then row_number() over (partition by acctid order by postdate)
end) PeriodCount


I was expecting PeriodCount to count [1,2,3] instead of [1,3,5], like so:



+--------+-------------+------------+-----------+-------------+
| Acctid | Transaction | PostDate | NetworkCd | PeriodCount |
+--------+-------------+------------+-----------+-------------+
| 12345 | Withdrawal | 10/4/2018 | FRGN | 1 |
| 12345 | Fee | 10/4/2018 | | |
| 12345 | Withdrawal | 10/11/2018 | FRGN | 2 |
| 12345 | Fee | 10/11/2018 | | |
| 12345 | Withdrawal | 10/22/2018 | FRGN | 3 |
| 12345 | Fee | 10/22/2018 | | |
+--------+-------------+------------+-----------+-------------+


What am I missing?










share|improve this question
























  • The row_number() is exactly that in this instance, the row number, whether you choose to display it or replace it with a null in the case statement, does not alter which row number it is.
    – Andrew
    Nov 19 at 15:35










  • @Andrew That was my first thought, but doesn't the case statement for networkcd is not null adjust for that?
    – sleven
    Nov 19 at 15:39










  • Afraid not, Dense_Rank as Alex has posted is the way forward, subtle difference in how it works
    – Andrew
    Nov 19 at 15:42















up vote
0
down vote

favorite












I am trying to add a ROW_NUMBER column to a data set that follows the order of [Withdrawal then Fee; Withdrawal then Fee] based upon whether the column NETWORKCD is null. However, my row_number formula is still counting Nulls even though it's not displaying the numbers, like so:



+--------+-------------+------------+-----------+-------------+
| Acctid | Transaction | PostDate | NetworkCd | PeriodCount |
+--------+-------------+------------+-----------+-------------+
| 12345 | Withdrawal | 10/4/2018 | FRGN | 1 |
| 12345 | Fee | 10/4/2018 | | |
| 12345 | Withdrawal | 10/11/2018 | FRGN | 3 |
| 12345 | Fee | 10/11/2018 | | |
| 12345 | Withdrawal | 10/22/2018 | FRGN | 5 |
| 12345 | Fee | 10/22/2018 | | |
+--------+-------------+------------+-----------+-------------+


I am using the following formula for PeriodCount



(case when networkcd is not null 
then row_number() over (partition by acctid order by postdate)
end) PeriodCount


I was expecting PeriodCount to count [1,2,3] instead of [1,3,5], like so:



+--------+-------------+------------+-----------+-------------+
| Acctid | Transaction | PostDate | NetworkCd | PeriodCount |
+--------+-------------+------------+-----------+-------------+
| 12345 | Withdrawal | 10/4/2018 | FRGN | 1 |
| 12345 | Fee | 10/4/2018 | | |
| 12345 | Withdrawal | 10/11/2018 | FRGN | 2 |
| 12345 | Fee | 10/11/2018 | | |
| 12345 | Withdrawal | 10/22/2018 | FRGN | 3 |
| 12345 | Fee | 10/22/2018 | | |
+--------+-------------+------------+-----------+-------------+


What am I missing?










share|improve this question
























  • The row_number() is exactly that in this instance, the row number, whether you choose to display it or replace it with a null in the case statement, does not alter which row number it is.
    – Andrew
    Nov 19 at 15:35










  • @Andrew That was my first thought, but doesn't the case statement for networkcd is not null adjust for that?
    – sleven
    Nov 19 at 15:39










  • Afraid not, Dense_Rank as Alex has posted is the way forward, subtle difference in how it works
    – Andrew
    Nov 19 at 15:42













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to add a ROW_NUMBER column to a data set that follows the order of [Withdrawal then Fee; Withdrawal then Fee] based upon whether the column NETWORKCD is null. However, my row_number formula is still counting Nulls even though it's not displaying the numbers, like so:



+--------+-------------+------------+-----------+-------------+
| Acctid | Transaction | PostDate | NetworkCd | PeriodCount |
+--------+-------------+------------+-----------+-------------+
| 12345 | Withdrawal | 10/4/2018 | FRGN | 1 |
| 12345 | Fee | 10/4/2018 | | |
| 12345 | Withdrawal | 10/11/2018 | FRGN | 3 |
| 12345 | Fee | 10/11/2018 | | |
| 12345 | Withdrawal | 10/22/2018 | FRGN | 5 |
| 12345 | Fee | 10/22/2018 | | |
+--------+-------------+------------+-----------+-------------+


I am using the following formula for PeriodCount



(case when networkcd is not null 
then row_number() over (partition by acctid order by postdate)
end) PeriodCount


I was expecting PeriodCount to count [1,2,3] instead of [1,3,5], like so:



+--------+-------------+------------+-----------+-------------+
| Acctid | Transaction | PostDate | NetworkCd | PeriodCount |
+--------+-------------+------------+-----------+-------------+
| 12345 | Withdrawal | 10/4/2018 | FRGN | 1 |
| 12345 | Fee | 10/4/2018 | | |
| 12345 | Withdrawal | 10/11/2018 | FRGN | 2 |
| 12345 | Fee | 10/11/2018 | | |
| 12345 | Withdrawal | 10/22/2018 | FRGN | 3 |
| 12345 | Fee | 10/22/2018 | | |
+--------+-------------+------------+-----------+-------------+


What am I missing?










share|improve this question















I am trying to add a ROW_NUMBER column to a data set that follows the order of [Withdrawal then Fee; Withdrawal then Fee] based upon whether the column NETWORKCD is null. However, my row_number formula is still counting Nulls even though it's not displaying the numbers, like so:



+--------+-------------+------------+-----------+-------------+
| Acctid | Transaction | PostDate | NetworkCd | PeriodCount |
+--------+-------------+------------+-----------+-------------+
| 12345 | Withdrawal | 10/4/2018 | FRGN | 1 |
| 12345 | Fee | 10/4/2018 | | |
| 12345 | Withdrawal | 10/11/2018 | FRGN | 3 |
| 12345 | Fee | 10/11/2018 | | |
| 12345 | Withdrawal | 10/22/2018 | FRGN | 5 |
| 12345 | Fee | 10/22/2018 | | |
+--------+-------------+------------+-----------+-------------+


I am using the following formula for PeriodCount



(case when networkcd is not null 
then row_number() over (partition by acctid order by postdate)
end) PeriodCount


I was expecting PeriodCount to count [1,2,3] instead of [1,3,5], like so:



+--------+-------------+------------+-----------+-------------+
| Acctid | Transaction | PostDate | NetworkCd | PeriodCount |
+--------+-------------+------------+-----------+-------------+
| 12345 | Withdrawal | 10/4/2018 | FRGN | 1 |
| 12345 | Fee | 10/4/2018 | | |
| 12345 | Withdrawal | 10/11/2018 | FRGN | 2 |
| 12345 | Fee | 10/11/2018 | | |
| 12345 | Withdrawal | 10/22/2018 | FRGN | 3 |
| 12345 | Fee | 10/22/2018 | | |
+--------+-------------+------------+-----------+-------------+


What am I missing?







sql plsql oracle11g






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 15:35









Juan Carlos Oropeza

35.5k63675




35.5k63675










asked Nov 19 at 15:33









sleven

225




225












  • The row_number() is exactly that in this instance, the row number, whether you choose to display it or replace it with a null in the case statement, does not alter which row number it is.
    – Andrew
    Nov 19 at 15:35










  • @Andrew That was my first thought, but doesn't the case statement for networkcd is not null adjust for that?
    – sleven
    Nov 19 at 15:39










  • Afraid not, Dense_Rank as Alex has posted is the way forward, subtle difference in how it works
    – Andrew
    Nov 19 at 15:42


















  • The row_number() is exactly that in this instance, the row number, whether you choose to display it or replace it with a null in the case statement, does not alter which row number it is.
    – Andrew
    Nov 19 at 15:35










  • @Andrew That was my first thought, but doesn't the case statement for networkcd is not null adjust for that?
    – sleven
    Nov 19 at 15:39










  • Afraid not, Dense_Rank as Alex has posted is the way forward, subtle difference in how it works
    – Andrew
    Nov 19 at 15:42
















The row_number() is exactly that in this instance, the row number, whether you choose to display it or replace it with a null in the case statement, does not alter which row number it is.
– Andrew
Nov 19 at 15:35




The row_number() is exactly that in this instance, the row number, whether you choose to display it or replace it with a null in the case statement, does not alter which row number it is.
– Andrew
Nov 19 at 15:35












@Andrew That was my first thought, but doesn't the case statement for networkcd is not null adjust for that?
– sleven
Nov 19 at 15:39




@Andrew That was my first thought, but doesn't the case statement for networkcd is not null adjust for that?
– sleven
Nov 19 at 15:39












Afraid not, Dense_Rank as Alex has posted is the way forward, subtle difference in how it works
– Andrew
Nov 19 at 15:42




Afraid not, Dense_Rank as Alex has posted is the way forward, subtle difference in how it works
– Andrew
Nov 19 at 15:42












3 Answers
3






active

oldest

votes

















up vote
3
down vote



accepted










It is still showing a value the 1st, 3rd and 5th rows - so the row count as it encounters each of those rows is correct. It's the row number within the entire result set, not within the not-null values. Your case expression is deciding whether to show the value, not affecting how it is found.



You could get the result you want using dense_rank() instead;



with your_table (Acctid, Transaction, PostDate, NetworkCd) as (
select 12345, 'Withdrawal', to_date('10/4/2018', 'MM/DD/YYYY'), 'FRGN' from dual
union all select 12345, 'Fee', to_date('10/4/2018', 'MM/DD/YYYY'), null from dual
union all select 12345, 'Withdrawal', to_date('10/11/2018', 'MM/DD/YYYY'), 'FRGN' from dual
union all select 12345, 'Fee', to_date('10/11/2018', 'MM/DD/YYYY'), null from dual
union all select 12345, 'Withdrawal', to_date('10/22/2018', 'MM/DD/YYYY'), 'FRGN' from dual
union all select 12345, 'Fee', to_date('10/22/2018', 'MM/DD/YYYY'), null from dual
)
select Acctid, Transaction, PostDate, NetworkCd,
(case when networkcd is not null then dense_rank() over (partition by acctid order by postdate) end) as periodcount
from your_table;

ACCTID TRANSACTIO POSTDATE NETW PERIODCOUNT
---------- ---------- ---------- ---- -----------
12345 Withdrawal 2018-10-04 FRGN 1
12345 Fee 2018-10-04
12345 Withdrawal 2018-10-11 FRGN 2
12345 Fee 2018-10-11
12345 Withdrawal 2018-10-22 FRGN 3
12345 Fee 2018-10-22


... as that does suppress gaps in the generated values. From the docs:




DENSE_RANK computes the rank of a row in an ordered group of rows and returns the rank as a NUMBER. The ranks are consecutive integers beginning with 1. ...







share|improve this answer























  • Works perfectly, thank you. I'll spend some time looking into Dense_rank().
    – sleven
    Nov 19 at 15:47


















up vote
0
down vote













ROW_NUMBER() function doesn't work as you expected, but you can do instead :



select t.*,
(select count(*)
from table t1
where t1.acctid = t.acctid and t1.PostDate <= t.PostDate and
t1.networkcd is not null
) as PeriodCount
from table t;





share|improve this answer




























    up vote
    0
    down vote













    It looks like instead of being NULL it is an empty string. SQL will regard that differently in the code.



    Try:



    case when networkcd = '' then row_number()....





    share|improve this answer





















    • Oracle Database treats a character value with a length of zero as null.. The result of comparing anything with = '' is the same as = null, which is 'unknown'.
      – Alex Poole
      Nov 20 at 17:07











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377925%2fconditional-row-number-to-skip-nulls-still-counting-them%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote



    accepted










    It is still showing a value the 1st, 3rd and 5th rows - so the row count as it encounters each of those rows is correct. It's the row number within the entire result set, not within the not-null values. Your case expression is deciding whether to show the value, not affecting how it is found.



    You could get the result you want using dense_rank() instead;



    with your_table (Acctid, Transaction, PostDate, NetworkCd) as (
    select 12345, 'Withdrawal', to_date('10/4/2018', 'MM/DD/YYYY'), 'FRGN' from dual
    union all select 12345, 'Fee', to_date('10/4/2018', 'MM/DD/YYYY'), null from dual
    union all select 12345, 'Withdrawal', to_date('10/11/2018', 'MM/DD/YYYY'), 'FRGN' from dual
    union all select 12345, 'Fee', to_date('10/11/2018', 'MM/DD/YYYY'), null from dual
    union all select 12345, 'Withdrawal', to_date('10/22/2018', 'MM/DD/YYYY'), 'FRGN' from dual
    union all select 12345, 'Fee', to_date('10/22/2018', 'MM/DD/YYYY'), null from dual
    )
    select Acctid, Transaction, PostDate, NetworkCd,
    (case when networkcd is not null then dense_rank() over (partition by acctid order by postdate) end) as periodcount
    from your_table;

    ACCTID TRANSACTIO POSTDATE NETW PERIODCOUNT
    ---------- ---------- ---------- ---- -----------
    12345 Withdrawal 2018-10-04 FRGN 1
    12345 Fee 2018-10-04
    12345 Withdrawal 2018-10-11 FRGN 2
    12345 Fee 2018-10-11
    12345 Withdrawal 2018-10-22 FRGN 3
    12345 Fee 2018-10-22


    ... as that does suppress gaps in the generated values. From the docs:




    DENSE_RANK computes the rank of a row in an ordered group of rows and returns the rank as a NUMBER. The ranks are consecutive integers beginning with 1. ...







    share|improve this answer























    • Works perfectly, thank you. I'll spend some time looking into Dense_rank().
      – sleven
      Nov 19 at 15:47















    up vote
    3
    down vote



    accepted










    It is still showing a value the 1st, 3rd and 5th rows - so the row count as it encounters each of those rows is correct. It's the row number within the entire result set, not within the not-null values. Your case expression is deciding whether to show the value, not affecting how it is found.



    You could get the result you want using dense_rank() instead;



    with your_table (Acctid, Transaction, PostDate, NetworkCd) as (
    select 12345, 'Withdrawal', to_date('10/4/2018', 'MM/DD/YYYY'), 'FRGN' from dual
    union all select 12345, 'Fee', to_date('10/4/2018', 'MM/DD/YYYY'), null from dual
    union all select 12345, 'Withdrawal', to_date('10/11/2018', 'MM/DD/YYYY'), 'FRGN' from dual
    union all select 12345, 'Fee', to_date('10/11/2018', 'MM/DD/YYYY'), null from dual
    union all select 12345, 'Withdrawal', to_date('10/22/2018', 'MM/DD/YYYY'), 'FRGN' from dual
    union all select 12345, 'Fee', to_date('10/22/2018', 'MM/DD/YYYY'), null from dual
    )
    select Acctid, Transaction, PostDate, NetworkCd,
    (case when networkcd is not null then dense_rank() over (partition by acctid order by postdate) end) as periodcount
    from your_table;

    ACCTID TRANSACTIO POSTDATE NETW PERIODCOUNT
    ---------- ---------- ---------- ---- -----------
    12345 Withdrawal 2018-10-04 FRGN 1
    12345 Fee 2018-10-04
    12345 Withdrawal 2018-10-11 FRGN 2
    12345 Fee 2018-10-11
    12345 Withdrawal 2018-10-22 FRGN 3
    12345 Fee 2018-10-22


    ... as that does suppress gaps in the generated values. From the docs:




    DENSE_RANK computes the rank of a row in an ordered group of rows and returns the rank as a NUMBER. The ranks are consecutive integers beginning with 1. ...







    share|improve this answer























    • Works perfectly, thank you. I'll spend some time looking into Dense_rank().
      – sleven
      Nov 19 at 15:47













    up vote
    3
    down vote



    accepted







    up vote
    3
    down vote



    accepted






    It is still showing a value the 1st, 3rd and 5th rows - so the row count as it encounters each of those rows is correct. It's the row number within the entire result set, not within the not-null values. Your case expression is deciding whether to show the value, not affecting how it is found.



    You could get the result you want using dense_rank() instead;



    with your_table (Acctid, Transaction, PostDate, NetworkCd) as (
    select 12345, 'Withdrawal', to_date('10/4/2018', 'MM/DD/YYYY'), 'FRGN' from dual
    union all select 12345, 'Fee', to_date('10/4/2018', 'MM/DD/YYYY'), null from dual
    union all select 12345, 'Withdrawal', to_date('10/11/2018', 'MM/DD/YYYY'), 'FRGN' from dual
    union all select 12345, 'Fee', to_date('10/11/2018', 'MM/DD/YYYY'), null from dual
    union all select 12345, 'Withdrawal', to_date('10/22/2018', 'MM/DD/YYYY'), 'FRGN' from dual
    union all select 12345, 'Fee', to_date('10/22/2018', 'MM/DD/YYYY'), null from dual
    )
    select Acctid, Transaction, PostDate, NetworkCd,
    (case when networkcd is not null then dense_rank() over (partition by acctid order by postdate) end) as periodcount
    from your_table;

    ACCTID TRANSACTIO POSTDATE NETW PERIODCOUNT
    ---------- ---------- ---------- ---- -----------
    12345 Withdrawal 2018-10-04 FRGN 1
    12345 Fee 2018-10-04
    12345 Withdrawal 2018-10-11 FRGN 2
    12345 Fee 2018-10-11
    12345 Withdrawal 2018-10-22 FRGN 3
    12345 Fee 2018-10-22


    ... as that does suppress gaps in the generated values. From the docs:




    DENSE_RANK computes the rank of a row in an ordered group of rows and returns the rank as a NUMBER. The ranks are consecutive integers beginning with 1. ...







    share|improve this answer














    It is still showing a value the 1st, 3rd and 5th rows - so the row count as it encounters each of those rows is correct. It's the row number within the entire result set, not within the not-null values. Your case expression is deciding whether to show the value, not affecting how it is found.



    You could get the result you want using dense_rank() instead;



    with your_table (Acctid, Transaction, PostDate, NetworkCd) as (
    select 12345, 'Withdrawal', to_date('10/4/2018', 'MM/DD/YYYY'), 'FRGN' from dual
    union all select 12345, 'Fee', to_date('10/4/2018', 'MM/DD/YYYY'), null from dual
    union all select 12345, 'Withdrawal', to_date('10/11/2018', 'MM/DD/YYYY'), 'FRGN' from dual
    union all select 12345, 'Fee', to_date('10/11/2018', 'MM/DD/YYYY'), null from dual
    union all select 12345, 'Withdrawal', to_date('10/22/2018', 'MM/DD/YYYY'), 'FRGN' from dual
    union all select 12345, 'Fee', to_date('10/22/2018', 'MM/DD/YYYY'), null from dual
    )
    select Acctid, Transaction, PostDate, NetworkCd,
    (case when networkcd is not null then dense_rank() over (partition by acctid order by postdate) end) as periodcount
    from your_table;

    ACCTID TRANSACTIO POSTDATE NETW PERIODCOUNT
    ---------- ---------- ---------- ---- -----------
    12345 Withdrawal 2018-10-04 FRGN 1
    12345 Fee 2018-10-04
    12345 Withdrawal 2018-10-11 FRGN 2
    12345 Fee 2018-10-11
    12345 Withdrawal 2018-10-22 FRGN 3
    12345 Fee 2018-10-22


    ... as that does suppress gaps in the generated values. From the docs:




    DENSE_RANK computes the rank of a row in an ordered group of rows and returns the rank as a NUMBER. The ranks are consecutive integers beginning with 1. ...








    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 19 at 15:47

























    answered Nov 19 at 15:40









    Alex Poole

    128k6100174




    128k6100174












    • Works perfectly, thank you. I'll spend some time looking into Dense_rank().
      – sleven
      Nov 19 at 15:47


















    • Works perfectly, thank you. I'll spend some time looking into Dense_rank().
      – sleven
      Nov 19 at 15:47
















    Works perfectly, thank you. I'll spend some time looking into Dense_rank().
    – sleven
    Nov 19 at 15:47




    Works perfectly, thank you. I'll spend some time looking into Dense_rank().
    – sleven
    Nov 19 at 15:47












    up vote
    0
    down vote













    ROW_NUMBER() function doesn't work as you expected, but you can do instead :



    select t.*,
    (select count(*)
    from table t1
    where t1.acctid = t.acctid and t1.PostDate <= t.PostDate and
    t1.networkcd is not null
    ) as PeriodCount
    from table t;





    share|improve this answer

























      up vote
      0
      down vote













      ROW_NUMBER() function doesn't work as you expected, but you can do instead :



      select t.*,
      (select count(*)
      from table t1
      where t1.acctid = t.acctid and t1.PostDate <= t.PostDate and
      t1.networkcd is not null
      ) as PeriodCount
      from table t;





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        ROW_NUMBER() function doesn't work as you expected, but you can do instead :



        select t.*,
        (select count(*)
        from table t1
        where t1.acctid = t.acctid and t1.PostDate <= t.PostDate and
        t1.networkcd is not null
        ) as PeriodCount
        from table t;





        share|improve this answer












        ROW_NUMBER() function doesn't work as you expected, but you can do instead :



        select t.*,
        (select count(*)
        from table t1
        where t1.acctid = t.acctid and t1.PostDate <= t.PostDate and
        t1.networkcd is not null
        ) as PeriodCount
        from table t;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 15:39









        Yogesh Sharma

        26.7k51335




        26.7k51335






















            up vote
            0
            down vote













            It looks like instead of being NULL it is an empty string. SQL will regard that differently in the code.



            Try:



            case when networkcd = '' then row_number()....





            share|improve this answer





















            • Oracle Database treats a character value with a length of zero as null.. The result of comparing anything with = '' is the same as = null, which is 'unknown'.
              – Alex Poole
              Nov 20 at 17:07















            up vote
            0
            down vote













            It looks like instead of being NULL it is an empty string. SQL will regard that differently in the code.



            Try:



            case when networkcd = '' then row_number()....





            share|improve this answer





















            • Oracle Database treats a character value with a length of zero as null.. The result of comparing anything with = '' is the same as = null, which is 'unknown'.
              – Alex Poole
              Nov 20 at 17:07













            up vote
            0
            down vote










            up vote
            0
            down vote









            It looks like instead of being NULL it is an empty string. SQL will regard that differently in the code.



            Try:



            case when networkcd = '' then row_number()....





            share|improve this answer












            It looks like instead of being NULL it is an empty string. SQL will regard that differently in the code.



            Try:



            case when networkcd = '' then row_number()....






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 19 at 15:49









            MapinTX

            106




            106












            • Oracle Database treats a character value with a length of zero as null.. The result of comparing anything with = '' is the same as = null, which is 'unknown'.
              – Alex Poole
              Nov 20 at 17:07


















            • Oracle Database treats a character value with a length of zero as null.. The result of comparing anything with = '' is the same as = null, which is 'unknown'.
              – Alex Poole
              Nov 20 at 17:07
















            Oracle Database treats a character value with a length of zero as null.. The result of comparing anything with = '' is the same as = null, which is 'unknown'.
            – Alex Poole
            Nov 20 at 17:07




            Oracle Database treats a character value with a length of zero as null.. The result of comparing anything with = '' is the same as = null, which is 'unknown'.
            – Alex Poole
            Nov 20 at 17:07


















             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377925%2fconditional-row-number-to-skip-nulls-still-counting-them%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            Refactoring coordinates for Minecraft Pi buildings written in Python