sql >> Base de Datos >  >> Database Tools >> phpMyAdmin

mysql:ORDENAR POR número de ocurrencias de un elemento en una columna de la tabla mysql

SELECT x.* 
  FROM my_table x 
  JOIN (SELECT location, COUNT(*) total FROM my_table GROUP BY location) y
    ON y.location = x.location
 ORDER 
    BY total DESC
     , id;