I have the below clause in a select statement
ROW_NUMBER() OVER(
PARTITION BY pc
ORDER BY
a DESC, b DESC
) r
How can I apply that function only to the rows which fulfill a certain condition but without filtering the selection at the end in a where clause? .
Sample data:
| PC | A | B |
|---|---|---|
| pc1 | a1 | b1 |
| pc1 | a2 | b2 |
| pc1 | a3 | b3 |
Desired output (the condition in this case would be where a2!='a2'):
| PC | A | B | R |
|---|---|---|---|
| pc1 | a1 | b1 | 1 |
| pc1 | a2 | b2 | null |
| pc1 | a3 | b3 | 2 |
EDIT: I've tried the below, but it does not start from 1 but from the whole rownum count.
CASE
WHEN condition THEN
ROW_NUMBER() OVER(
PARTITION BY pc
ORDER BY
a, b
)
END r1