Order By¶
Sort a result with .order_by([cols], desc) on the Select
builder. The first argument is the list of columns to sort by; the second is a
bool — true for descending, false for ascending.
Assume a live runtime and the trades table
Descending sort¶
let r = t
.select()
.col("price")
.order_by(["price"], true) // descending
.execute()?;
println!("{r}");
┌─────────────────────────────────────┐
│ price │
│ F64 │
├─────────────────────────────────────┤
│ 300.0 │
│ 210.0 │
│ 200.0 │
│ 110.0 │
│ 100.0 │
├─────────────────────────────────────┤
│ 5 rows (5 shown) 1 columns (1 shown)│
└─────────────────────────────────────┘
Ascending sort¶
Pass false for ascending order:
Multiple sort columns¶
Provide more than one column to sort by the first, breaking ties with the next:
Chaining with other operations¶
.order_by composes with filtering, grouping, and
projection. It applies to the final result:
let r = t
.select()
.cols(["sym", "price"])
.filter(col("price").gt(150.0))
.order_by(["price"], true)
.execute()?;
Continue with Update to modify table columns.