SELECT code
FROM lock
ORDER BY CAST(code AS signed) > 0 DESC, CAST(code AS signed) ASC, code ASC
First order sorts the numbers in front. The second order will only sort the numbers ascending, while the first will keep them at the beginning. The third one will sort the lines only in ascending order, the numbers will keep their order, because they are already sorted.
source
share