178 Rank Scores

-- "dataframe to relation feature" is needed

rank := :showdataframe scores{score} orderby{score descending}
┌──┬──────────────┐
│DF│score::Double⬇│
├──┼──────────────┤
│1 │4.0           │
│2 │3.85          │
│3 │3.65          │
│4 │3.5           │
└──┴──────────────┘


:showexpr scores join rank
┌───────────┬───────────┬─────────────┐
│df::Integer│id::Integer│score::Double│
├───────────┼───────────┼─────────────┤
│1          │5          │4.0          │
│3          │2          │3.65         │
│4          │1          │3.5          │
│3          │6          │3.65         │
│1          │3          │4.0          │
│2          │4          │3.85         │
└───────────┴───────────┴─────────────┘


:showdataframe (scores join rank) orderby {df ascending}

┌──┬────────────┬────────────┬──────────────┐
│DF│df::Integer⬆│id::Integer↕│score::Double↕│
├──┼────────────┼────────────┼──────────────┤
│1 │1           │3           │4.0           │
│2 │1           │5           │4.0           │
│3 │2           │4           │3.85          │
│4 │3           │6           │3.65          │
│5 │3           │2           │3.65          │
│6 │4           │1           │3.5           │
└──┴────────────┴────────────┴──────────────┘

-- a feature to fix attribute order may be needed

留言

這個網誌中的熱門文章

LeetCode 184. Department Highest Salary