pub fn lead<T: SqlType + SingleValue + IntoNullable<Nullable: SingleValue>, value>(
value: value,
) -> lead<T, <value as AsExpression<T>>::Expression>where
value: AsExpression<T>,
Expand description
Value of argument from row leading current row within partition
Returns value evaluated at the row that is offset rows after the current
row within the partition; if there is no such row,
NULL
will be returned instead.
See lead_with_offset
and lead_with_offset_and_default
for variants with configurable offset
and default values.
This function must be used as window function. You need to call at least one
of the methods WindowExpressionMethods
from to use this function in your SELECT
clause. It cannot be used outside of SELECT
clauses.
For MySQL this function requires you to call .window_order()
let res = posts
.select((
title,
user_id,
lead(id).partition_by(user_id).window_order(user_id),
))
.load::<(String, i32, Option<i32>)>(connection)?;
let expected = vec![
("My first post".to_owned(), 1, Some(2)),
("About Rust".into(), 1, None),
("My first post too".into(), 2, None),
];
assert_eq!(expected, res);