ST_Collect([DISTINCT] g) [over_clause]

Aggregates geometry values and returns a single geometry collection
value. With the DISTINCT option, returns the aggregation of the
distinct geometry arguments.

As with other aggregate functions, GROUP BY may be used to group
arguments into subsets. ST_Collect() returns an aggregate value for
each subset.

This function executes as a window function if over_clause is present.
over_clause is as described in
https://dev.mysql.com/doc/refman/8.4/en/window-functions-usage.html. In
contrast to most aggregate functions that support windowing,
ST_Collect() permits use of over_clause together with DISTINCT.

ST_Collect() handles its arguments as follows:

o NULL arguments are ignored.

o If all arguments are NULL or the aggregate result is empty, the
  return value is NULL.

o If any geometry argument is not a syntactically well-formed geometry,
  an ER_GIS_INVALID_DATA
  (https://dev.mysql.com/doc/mysql-errors/8.4/en/server-error-reference
  .html#error_er_gis_invalid_data) error occurs.

o If any geometry argument is a syntactically well-formed geometry in
  an undefined spatial reference system (SRS), an ER_SRS_NOT_FOUND
  (https://dev.mysql.com/doc/mysql-errors/8.4/en/server-error-reference
  .html#error_er_srs_not_found) error occurs.

o If there are multiple geometry arguments and those arguments are in
  the same SRS, the return value is in that SRS. If those arguments are
  not in the same SRS, an ER_GIS_DIFFERENT_SRIDS_AGGREGATION
  (https://dev.mysql.com/doc/mysql-errors/8.4/en/server-error-reference
  .html#error_er_gis_different_srids_aggregation) error occurs.

o The result is the narrowest MultiXxx or GeometryCollection value
  possible, with the result type determined from the non-NULL geometry
  arguments as follows:

  o If all arguments are Point values, the result is a MultiPoint
    value.

  o If all arguments are LineString values, the result is a
    MultiLineString value.

  o If all arguments are Polygon values, the result is a MultiPolygon
    value.

  o Otherwise, the arguments are a mix of geometry types and the result
    is a GeometryCollection value.

URL: https://dev.mysql.com/doc/refman/8.4/en/spatial-aggregate-functions.html

