ORDER BY (EN)

Concept

Clause for sorting rows in Window Functions

Definition

ORDER BY is a clause in Window Functions that determines the order of rows within a partition. This sorting determines the calculation order for functions such as rankings or moving averages. The correct use of ORDER BY is crucial for predictable results in Window Functions as it defines the processing of the rows.

Example

  • Typically used together with OVER() and Window Functions such as ROW_NUMBER(), RANK() or LAG()
  • Related to: PARTITION BY, Window Functions, SQL
  • Example usage: SELECT employee_id, salary, ROW_NUMBER() OVER (ORDER BY salary DESC) as rank FROM employees;
Quelle: AI Generated