First, a link to the docs. However, it is somewhat unclear.
The analytic clause consists of query_partition_clause , order_by_clause and windowing_clause . And the really important thing in windowing_clause is
You cannot specify this section if you did not specify order_by_clause . Some window borders defined in the RANGE clause you can specify only one expression in order_by_clause . Refer to "Constraints in the ORDER BY Clause".
But you cannot help using windowing_clause without order_by_clause , they are related to each other.
If you omit windowing_clause completely, RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW used by default.
The default windowing clause creates something like total execution. COUNT returns 1 for the first line, since there is only one line between the top of the window and the current line, 2 for the second line, etc.
So, in your first request there is no window at all, but in the second there is a default window.
And you can simulate the behavior of the first request by specifying a completely unlimited window.
with req as (select 1 as n, 'A' as cls from dual union select 2 as n, 'A' as cls from dual) select req.*, count(*) over(partition by cls order by n RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as cnt from req;
Yes
N CLS CNT 1 A 2 2 A 2
That young man
source share