pub fn rank() -> rank
Expand description
Rank of current row within its partition, with gaps
Returns the rank of the current row, with gaps; that is, the row_number of the first row in its peer group.
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,
rank().partition_by(user_id).window_order(user_id),
))
.load::<(String, i32, i64)>(connection)?;
let expected = vec![
("My first post".to_owned(), 1, 1),
("About Rust".into(), 1, 1),
("My first post too".into(), 2, 1),
];
assert_eq!(expected, res);