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?
sql plsql oracle11g
add a comment |
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?
sql plsql oracle11g
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
add a comment |
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?
sql plsql oracle11g
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
sql plsql oracle11g
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
add a comment |
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
add a comment |
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 aNUMBER
. The ranks are consecutive integers beginning with 1. ...
Works perfectly, thank you. I'll spend some time looking into Dense_rank().
– sleven
Nov 19 at 15:47
add a comment |
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;
add a comment |
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()....
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
add a comment |
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 aNUMBER
. The ranks are consecutive integers beginning with 1. ...
Works perfectly, thank you. I'll spend some time looking into Dense_rank().
– sleven
Nov 19 at 15:47
add a comment |
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 aNUMBER
. The ranks are consecutive integers beginning with 1. ...
Works perfectly, thank you. I'll spend some time looking into Dense_rank().
– sleven
Nov 19 at 15:47
add a comment |
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 aNUMBER
. The ranks are consecutive integers beginning with 1. ...
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 aNUMBER
. The ranks are consecutive integers beginning with 1. ...
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
add a comment |
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
add a comment |
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;
add a comment |
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;
add a comment |
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;
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;
answered Nov 19 at 15:39
Yogesh Sharma
26.7k51335
26.7k51335
add a comment |
add a comment |
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()....
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
add a comment |
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()....
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
add a comment |
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()....
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()....
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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