CREATE TABLE product (year INTEGER,product VARCHAR(256),location Geometry);INSERT INTO product(year, product, location) VALUES(2000, "Calculator", ST_GeomFromText('point(60 -24)',4326)),(2000, "Computer" , ST_GeomFromText('point(28 -77)',4326)),(2000, "Abacus" , ST_GeomFromText('point(28 -77)',4326)),(2000, "TV" , ST_GeomFromText('point(38 60)',4326)),(2001, "Calculator", ST_GeomFromText('point(60 -24)',4326)),(2001, "Computer" , ST_GeomFromText('point(28 -77)',4326));
mysql> SELECT ST_AsText(ST_Collect(location)) AS resultFROM product;+------------------------------------------------------------------+| result |+------------------------------------------------------------------+| MULTIPOINT((60 -24),(28 -77),(28 -77),(38 60),(60 -24),(28 -77)) |+------------------------------------------------------------------+mysql> SELECT ST_AsText(ST_Collect(DISTINCT location)) AS resultFROM product;+---------------------------------------+| result |+---------------------------------------+| MULTIPOINT((60 -24),(28 -77),(38 60)) |+---------------------------------------+mysql> SELECT year, ST_AsText(ST_Collect(location)) AS resultFROM product GROUP BY year;+------+------------------------------------------------+| year | result |+------+------------------------------------------------+| 2000 | MULTIPOINT((60 -24),(28 -77),(28 -77),(38 60)) || 2001 | MULTIPOINT((60 -24),(28 -77)) |+------+------------------------------------------------+mysql> SELECT year, ST_AsText(ST_Collect(DISTINCT location)) AS resultFROM product GROUP BY year;+------+---------------------------------------+| year | result |+------+---------------------------------------+| 2000 | MULTIPOINT((60 -24),(28 -77),(38 60)) || 2001 | MULTIPOINT((60 -24),(28 -77)) |+------+---------------------------------------+# selects nothingmysql> SELECT ST_Collect(location) AS resultFROM product WHERE year = 1999;+--------+| result |+--------+| NULL |+--------+mysql> SELECT ST_AsText(ST_Collect(location)OVER (ORDER BY year, product ROWS BETWEEN 1 PRECEDING AND CURRENT ROW))AS resultFROM product;+-------------------------------+| result |+-------------------------------+| MULTIPOINT((28 -77)) || MULTIPOINT((28 -77),(60 -24)) || MULTIPOINT((60 -24),(28 -77)) || MULTIPOINT((28 -77),(38 60)) || MULTIPOINT((38 60),(60 -24)) || MULTIPOINT((60 -24),(28 -77)) |+-------------------------------+
此函数是在MySQL 8.0.24中添加的。
文章转载自林员外聊编程,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




