Opret et sammensat indeks på (state, city)
og omskriv din forespørgsel som denne:
SELECT CONCAT_WS(', ', city, state) AS location, AVG(latitude), AVG(longitude)
FROM places
WHERE state='NY'
AND city='New York'
GROUP BY
state, city
Bemærk, at for netop denne forespørgsel kan du udelade GROUP BY
klausul:
SELECT 'New York, NY' AS location, AVG(latitude), AVG(longitude)
FROM places
WHERE state='NY'
AND city='New York'
Denne forespørgsel har dog stadig brug for den:
SELECT CONCAT_WS(', ', city, state) AS location, AVG(latitude), AVG(longitude)
FROM places
WHERE state='NY'
GROUP BY
state, city