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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -