php - ms sql row_number() function - won't let me use within the same statement -
i have following sql statement:
$sql = "select siteid, row_number() on (order siteid) rownum nwsite rownum >= 4";
"rownum" works when use name outside of query (e.g. in foreach loop) when comes using clause never works.
any ideas?
thanks
because clause evaluated before window function row_number computed, can't include column in clause.
you can structure query this:
select siteid, rownum (select siteid, row_number() on (order siteid) rownum nwsite) nw rownum >= 4
in case inner query computed in entirety , passed outer query rownum column can acted upon.
Comments
Post a Comment