Consider table t:
x  y
1  2
3  4
And the somewhat naive query
SELECT
    ROW_NUMBER() OVER ( ORDER BY x ) row_num,
    x,
    y
FROM
    t
WHERE
    x = 3;
Which (understandably) outputs
row_num x  y
1       3  4
However, I want
row_num x  y
2       3  4
(row_num should be "calculated" over the unfiltered table, so before the WHERE clause is applied)
I tried
SELECT
    ROW_NUMBER() OVER ( ORDER BY t.x ) row_num,
    t1.x,
    t1.y 
FROM
    t, t as t1
WHERE
    t.x = t1.x AND t1.x = 3;
But I get the exact same output.
Will ROW_NUMBER always execute last, or is there a way to force it to execute first, then apply the WHERE clause?
 
     
    