Cómo combinar GROUP BY, ORDER BY y HAVING

¿Cómo combino correctamente esta statement?

SELECT *, COUNT(*) FROM user_log GROUP BY Email ORDER BY UpdateDate DESC HAVING COUNT(*) > 1 

Házmelo saber

ORDER BY siempre es el último …

Sin embargo, debe elegir los campos que REALMENTE QUIERE, luego seleccionar solo aquellos y agruparlos. SELECT * y GROUP BY Email le darán VALORES ALEATORIOS para todos los campos excepto Email . La mayoría de RDBMS ni siquiera le permitirá hacer esto debido a los problemas que crea, pero MySQL es la exception.

 SELECT Email, COUNT(*) FROM user_log GROUP BY Email HAVING COUNT(*) > 1 ORDER BY UpdateDate DESC 

Tu código debe contener WHILE antes de group by y having :

 SELECT Email, COUNT(*) FROM user_log WHILE Email IS NOT NULL GROUP BY Email HAVING COUNT(*) > 1 ORDER BY UpdateDate DESC 

Pasos para usar Group by, Having By y Order by …

 Select Attitude ,count(*) from Person group by person HAving PersonAttitude='cool and friendly' Order by PersonName.