Здесь вы можете найти пример удаления маркеров:
https://developers.google.com/maps/documentation/javascript/examples/marker-remove?hl=es
// Add a marker to the map and push to the array.
function addMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
markers.push(marker);
}
// Sets the map on all markers in the array.
function setAllMap(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
// Removes the markers from the map, but keeps them in the array.
function clearMarkers() {
setAllMap(null);
}
// Deletes all markers in the array by removing references to them.
function deleteMarkers() {
clearMarkers();
markers = [];
}
Вот простой способ - просто измените новое, чтобы оно выглядело как старое:
Обратите внимание, это было отредактировано для использования CTE, так как у вас был подзапрос с подсчетом.
WITH flagevent_comb as (
SELECT user, country, COUNT(DISTINCT country) as cnt
FROM (
SELECT user, country1 AS country FROM flagevent WHERE country1 IS NOT NULL
UNION ALL
SELECT user, country2 AS country FROM flagevent WHERE country2 IS NOT NULL
) x
GROUP BY user, country
)
SELECT f.cnt as totalflags,
GROUP_CONCAT(DISTINCT(country) ORDER BY c.name) AS allcountries,
f.user, u.username
FROM flagevent_comb AS f
INNER JOIN country AS c ON f.country = c.code
INNER JOIN user AS u ON f.user = u.id
WHERE f.user = 1
OR f.user in (1, 2, 3)
GROUP BY user
ORDER BY totalflags DESC;
Обратите внимание, что вам, возможно, придется усложнить подзапрос. Например, если иногда страна1 или страна2 равны нулю, это, вероятно, будет лучше.
SELECT user, country1 AS country FROM flagevent WHERE country1 IS NOT NULL
UNION ALL
SELECT user, country2 AS country FROM flagevent WHERE country2 IS NOT NULL
Могут применяться и другие бизнес-правила.