SQL - When will an empty OVER clause be used?

I am analyzing some code that uses empty OVER clauses in the Count () contest.

Example:

SELECT 
        ROW_NUMBER() OVER (ORDER BY Priority DESC) AS RowID,
        CAST((COUNT(*) OVER() / @pagesize) AS Int) AS TotalPages,

I am trying to understand why the empty OVER clause is used here.

There are other standard selection elements below the two lines listed above, and when I remove the empty OVER clause from the second line of TotalPages, I get errors like this:

Column 'TableA.Priority' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

As soon as I returned OVER (), the error disappeared.

My understanding of the OVER clause is very limited ... I feel, As I understand it, what happens on the RowID line ... but the TotalPages line just puzzles me.

+3
source share
1 answer

OVER() . OVER() -

. COUNT (*) OVER() .

http://msdn.microsoft.com/en-us/library/ms189461.aspx

+8

Source: https://habr.com/ru/post/1756991/


All Articles