Buat indeks komposit di (state, city)
dan tulis ulang kueri Anda seperti ini:
SELECT CONCAT_WS(', ', city, state) AS location, AVG(latitude), AVG(longitude)
FROM places
WHERE state='NY'
AND city='New York'
GROUP BY
state, city
Perhatikan bahwa untuk kueri ini Anda dapat menghilangkan GROUP BY
klausa:
SELECT 'New York, NY' AS location, AVG(latitude), AVG(longitude)
FROM places
WHERE state='NY'
AND city='New York'
Namun, kueri ini masih membutuhkannya:
SELECT CONCAT_WS(', ', city, state) AS location, AVG(latitude), AVG(longitude)
FROM places
WHERE state='NY'
GROUP BY
state, city