pub fn nth_value<T: SqlType + SingleValue + IntoNullable<Nullable: SingleValue>, value, n>(
value: value,
n: n,
) -> nth_value<T, <value as AsExpression<T>>::Expression, <n as AsExpression<Integer>>::Expression>
Expand description
Value of argument from N-th row of window frame
Returns value evaluated at the row that is the n’th row of the window frame (counting from 1); returns NULL if there is no such row.
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.
let res = posts
.select((title, user_id, nth_value(id, 2).partition_by(user_id)))
.load::<(String, i32, Option<i32>)>(connection)?;
let expected = vec![
("My first post".to_owned(), 1, Some(2)),
("About Rust".into(), 1, Some(2)),
("My first post too".into(), 2, None),
];
assert_eq!(expected, res);