Obtenga el valor más alto de la fila - MySQL

Tengo esta consulta:

SELECT tag, filename, timecode, COUNT(tag) AS total 
FROM dados 
WHERE dados.tag = 'movie' 
AND dados.filename = 'movie2.mp4' 
GROUP BY timecode

Y este es el resultado:

But i only want the 3rd row, more precisely the timecode=2 because it's the most consisting tag with the higher value. How can i grab the highest value of timecode from those rows?

preguntado el 24 de agosto de 12 a las 22:08

1 Respuestas

Utilice las ORDER BY con LIMIT

SELECT tag, filename, timecode, COUNT(tag) AS total 
FROM dados 
WHERE dados.tag = 'movie' 
AND dados.filename = 'movie2.mp4' 
GROUP BY timecode
ORDER BY COUNT(tag) DESC
LIMIT 1

Respondido 24 ago 12, 22:08

I'm not sure if limit will work together with group by. If limit works, I would sugest to add a 'limit 1' - Christian Kuetbach

If you use it with LIMIT it will do what you need - John Conde

He wants the row with the highest COUNT(tag), not highest timecode. - Dan Grossman

If i use the limit like John said it will print this: 'movie', 'movie2.mp4', '6', '3' - zppinto

Cambiarlo a ORDER BY COUNT(tag) DESC. - Dan Grossman

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.