Skip to main content

percent_rank

Knowledge Checkpoint

Readings that will help you understand this documentation better:

Definition

Returns the relative percentile of a row within a partition of a table. The value is between 0 and 1, inclusive.

Syntax

percent_rank(order: order_expr, ...)
percent_rank(order: order_expr, ..., partition: partition_expr, ...)
Examples
percent_rank(order: count(orders.id) | desc())
percent_rank(order: count(orders.id) | desc(), order: average(users.age))

// with partition
percent_rank(order: count(orders.id) | desc(), partition: orders.status)

Input

  • 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. percent_rank(order: count(orders.id) | desc())
  • partition (repeatable, optional): A field that is used for partitioning the table. E.g. percent_rank(order: count(orders.id), partition: orders.status)

Output

The percentile rank of the current row within its partition, as a value between 0 and 1. If no partition is specified, the whole table is considered as a single partition.


Let us know what you think about this document :)