We can use aggregate function ST_Collect()
since MySQL 8.0.24.
It supports DISTINCT
and OVER
clause, and generates automagically a MULTIPOINT
:
SELECT ALL
SubjectID,
ST_Collect(fix_geom),
ST_AsText(ST_Collect(fix_geom)) -- MULTIPOINT((...),(...),...)
FROM ...
WHERE ...
GROUP BY 1
If you store points separately and/or need a GeoJSON :
SELECT ALL
SubjectID,
ST_Collect(Point(latitude, longitude)),
ST_AsGeoJSON(ST_Collect(Point(latitude, longitude))) -- {"type": "MultiPoint", "coordinates": [...]}
FROM ...
WHERE ...
GROUP BY 1
https://dev.mysql.com/doc/refman/8.0/en/spatial-aggregate-functions.html