views:

47

answers:

1

a) Quote is taken from http://www.postgresql.org/docs/current/static/tutorial-window.html

for each row, there is a set of rows within its partition called its window frame. Many (but not all) window functions act only on the rows of the window frame, rather than of the whole partition. By default, if ORDER BY is supplied then the frame consists of all rows from the start of the partition up through the current row, plus any following rows that are equal to the current row according to the ORDER BY clause

I assume Row_Number doesn’t act only on rows of the window frame, but instead always act on all rows of a partition?

b)

By default, if ORDER BY is supplied then the frame consists of all rows from the start of the partition up through the current row, plus any following rows that are equal to the current row according to the ORDER BY clause

I assume that is only true for those window functions that act only on rows of the window frame ( thus above quote isn't true for ROW_NUMBER() function )?

c) http://www.postgresql.org/docs/current/static/tutorial-window.html talks about PostgreSQL 8.4’s Windowing functions. Is everything in that article also true for Sql Server 2008’s Windowing functions

thanx

+2  A: 

The ORDER BY clause in aggregate window functions is not supported by SQL Server yet. http://msdn.microsoft.com/en-us/library/ms189461.aspx

The below query will give you a syntax error

SELECT salary, sum(salary) OVER (ORDER BY salary) FROM empsalary

row_number() is not an aggregate window function so it does not act on rows of the window frame only. It acts on the whole partition. Only aggregate functions work on the window frame. And only if the ORDER BY clause is supported.

Chris Bednarski
"The ORDER BY clause in aggregate window functions is not supported by SQL Server yet."But my question was whether ROW_NUMBER acts on rows of window frame, and as far as I know, ROW_NUMBER() is not an aggregate windows function
AspOnMyNet
Sorry. I'll edit my answer.
Chris Bednarski
I thought NTILE and RANK also act on rows of window frame ( I haven't yet covered those functions,but I thought I've read somewhere that they do )?
AspOnMyNet
Window frame support appears to be limited to non ranking functions in other products as well. However, I haven't read the ANSI standard, so can't tell for sure. http://publib.boulder.ibm.com/infocenter/rbhelp/v6r3/index.jsp?topic=/com.ibm.redbrick.doc6.3/sqlrg/sqlrg36.htmWindow frames are not supported in MS SQL 2008 at all. ANSI SQL syntax like ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW will fail.
Chris Bednarski
ok, thank you for your help
AspOnMyNet