2
To Documentation says :
Determines partitioning and sorting of the row set before application of the associated window function.
An example I created just to demonstrate this:
select ROW_NUMBER() OVER(PARTITION BY cor order by carro ) from carro
This example would return a ROW_NUMBER
counting until changing the condition of the column and restarting . In a table of 7 records with 2 records with the color yellow and 5 with the color blue Row_Number
would go from 1 to 2 and reboot and would go from 1 to 5 again.
However for some aggregation functions, no partitioning is required to use this condition, for example this select found here:
SELECT MAX(date) OVER (ORDER BY id)
FROM mytable
But for clauses with partition of values the order by is required, but the partition is not, it depends on the function it is calling, so:
- When should I use the clause
OVER
? - The
Group By
at the end of a select works the same way(in cases of partition)? - When I can use over functions without an order by, there are specific functions that allow this?
There is a question in SOEN but I found very generic the answer so I continue with some doubts.
Other references:
The answer is in the question itself: window function. See article "Window functions (functions window)", in the SQL Port: https://portosql.wordpress.com/2018/10/14/funcoes-de-janela-window-functions/
– José Diz
@Josédiz will see, today I already have a better knowledge and I know how to use better so the explanation will make more sense
– Daniel Gentil