Skip to content

Instantly share code, notes, and snippets.

@jgdoncel
Created July 30, 2014 12:08
Show Gist options
  • Save jgdoncel/8b9d922f36bb5127c0da to your computer and use it in GitHub Desktop.
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
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