Skip to main content

first_value

Knowledge Checkpoint

Readings that will help you understand this documentation better:

Definition

Returns the value of an expression from the first row of the window frame.

Syntax

first_value(expr, order: order_expr, ...)
first_value(expr, order: order_expr, ..., partition: partition_expr, ...)
Examples
first_value(count(orders.id), order: users.created_at | asc())
first_value(count(orders.id), order: users.created_at | asc(), order: users.id)

// with partition
first_value(count(orders.id), order: users.created_at | asc(), partition: orders.status)

Input

  • expr (required): The expression to retrieve the first value from.
  • order (required, repeatable): A field that is used for ordering. The order is default to ascending. The order can be set explicitly with asc() or desc(). E.g. first_value(count(orders.id), order: users.created_at | desc())
  • partition (repeatable, optional): A field that is used for partitioning the table. E.g. first_value(count(orders.id), order: users.created_at, partition: orders.status)

Output

The value of the expression from the first row of the window frame. If no partition is specified, the whole table is considered as a single partition.


Let us know what you think about this document :)