Created
July 30, 2014 12:08
-
-
Save jgdoncel/8b9d922f36bb5127c0da to your computer and use it in GitHub Desktop.
Casteo de campo para ordenar: tenemos un campo varchar, filtramos sólo los registros con valores numéricos y ordenamos con casteo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT id, nombre, apellidos, SUBSTR(CONCAT('0000',codigo),-4) as CDB FROM empleados WHERE codigo REGEXP '^-?[0-9]+$' ORDER BY CAST(codigo AS UNSIGNED) ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment