cume_dist

Function cume_dist 

Source
pub fn cume_dist() -> cume_dist
Expand description

Cumulative distribution value

Returns the cumulative distribution, that is (number of partition rows preceding or peers with current row) / (total partition rows). The value thus ranges from 1/N to 1.

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