これが非常に効率的かどうかはわかりませんが、1つのクエリで機能します :
UPDATE t
JOIN (
SELECT MAX(t.id) AS maxid, lat, lon
FROM t
JOIN t AS duplicates
USING (lat, lon)
GROUP BY lat, lon
HAVING COUNT(*) > 1
) AS maxima USING (lat, lon)
SET flag = IF(id = maxid, 1, 2);
これが非常に効率的かどうかはわかりませんが、1つのクエリで機能します :
UPDATE t
JOIN (
SELECT MAX(t.id) AS maxid, lat, lon
FROM t
JOIN t AS duplicates
USING (lat, lon)
GROUP BY lat, lon
HAVING COUNT(*) > 1
) AS maxima USING (lat, lon)
SET flag = IF(id = maxid, 1, 2);