seleccionando la marca de tiempo máxima cuando la marca de tiempo es un campo de texto
Frecuentes
Visto 230 veces
1
I am trying select the max timestamp value for a field that contains timestamp values, but is actually a text field. Before you say it, I can't change the field type because the app that populates it is not changeable. It's annoying, I know.
The format of the Timestamp is
Wed Mar 02 13:28:59 CST 2011 -> this is actually a text value in MYSQL
Aquí está mi intento:
SELECT DISTINCT MAX(STR_TO_DATE(`Timestamp`, '%d, %m, %Y')) FROM `table`
'Timestamp' is referring to the column called Timestamp.
This just returns NULL values for the timestamp. Thanks for any help.
4 Respuestas
1
This should work for you, also have a look at http://www.w3schools.com/sql/func_date_format.asp
SELECT DISTINCT MAX(STR_To_DATE(`Timestamp`,'%a %b %d %H:%i:%s CST %Y'))
FROM `table`;
Test case example:
SET @v = 'Wed Mar 02 13:28:59 CST 201';
SELECT STR_To_DATE(@v, '%a %b %d %H:%i:%s CST %Y');
Respondido 28 ago 12, 14:08
1
Prueba este formato
STR_TO_DATE(`Timestamp`,'%a %b %d %T CST %Y')
Respondido 28 ago 12, 14:08
1
Prueba esta consulta:
SELECT
MAX(STR_TO_DATE(`Timestamp`, '%a %b %d %H:%i:%s CST %Y'))
FROM
`table`
Respondido 28 ago 12, 14:08
0
Use
SELECT DISTINCT MAX(STR_TO_DATE(`table.Timestamp`, '%d, %m, %Y')) FROM `table`
Respondido 28 ago 12, 14:08
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas mysql or haz tu propia pregunta.
this didn't work :(. I think the format of the string is throwing it off. - hacha
putting the quotes around it gives an 'Unknown column' error. - hacha