Description
Need to add support for ordered-set and hypothetical-set aggregate functions, as well as implementations of the instances defined in SQL:2008 (percentile_cont(), percentile_disc(), rank(), dense_rank(), percent_rank(), cume_dist()). It is good to added mode() though it is not in the spec. In addition, you can gracefully solve the problem of element unordering in the LIST aggregate function (in the SQL standard LISTAGG).
Ordered-Set Aggregate Functions
MODE() WITHIN GROUP ( ORDER BY <order_expr>)
PERCENTILE_CONT( <expr> ) WITHIN GROUP ( ORDER BY <order_expr> )
PERCENTILE_DISC( <expr> ) WITHIN GROUP ( ORDER BY <order_expr>)
LIST(<expr>, <separator>) WITHIN GROUP(ORDER BY <order_expr>)
It is also possible to introduce the LISTAGG function, and make LIST an alias for compatibility with the standard.
Hypothetical-Set Aggregate Functions
RANK( <args> ) WITHIN GROUP ( ORDER BY <order_exprs> )
DENSE_RANK( <args> ) WITHIN GROUP ( ORDER BY <order_exprs> )
PERCENT_RANK( <args> ) WITHIN GROUP ( ORDER BY <order_exprs> )
CUME_DIST( <expr> ) WITHIN GROUP ( ORDER BY <order_exprs> )
You can read more about how this is done in PostgreSQL here.
https://www.postgresql.org/docs/current/functions-aggregate.html
https://paquier.xyz/postgresql-2/postgres-9-4-feature-highlight-within-group/