sql >> Base de Datos >  >> RDS >> Mysql

MySQL:GROUP_CONCAT con un ORDEN POR CONTEO?

Encontré una solución yo mismo, con una subconsulta:

SELECT 
  SUBSTRING_INDEX(
    GROUP_CONCAT(DISTINCT name ORDER BY CountName DESC SEPARATOR '||')
  , '||', 1),
  address,
  postalcode,
  place,
  phone
FROM (

  SELECT name, address, postalcode, place, phone , COUNT(name) AS CountName
  FROM addresses
  GROUP BY name, postalcode, phone
  ORDER BY COUNT(name) DESC

) as a
GROUP BY postalcode, phone

Me pregunto si se puede hacer sin una subconsulta.