ntile

Function ntile 

Source
pub fn ntile<num_buckets>(num_buckets: num_buckets) -> ntile<num_buckets>
where num_buckets: AsExpression<Integer>,
Expand description

Bucket number of current row within its partition

Returns an integer ranging from 1 to the argument value, dividing the partition as equally as possible.

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, ntile(2).partition_by(user_id)))
    .load::<(String, i32, i32)>(connection)?;
let expected = vec![
    ("My first post".to_owned(), 1, 1),
    ("About Rust".into(), 1, 2),
    ("My first post too".into(), 2, 1),
];
assert_eq!(expected, res);