2012. 4. 14. 14:18
출처: http://crodrigues.com/trick-mysql-order-string-as-number/
숫자와 문자가 섞어였는 것을 정렬하고 싶었는데, 자료가 없었다.
Trick 이긴하지만 매우 유용한 것
ORDER BY field+0 ASC
+0 이 대박인듯..ㅡㅡ;;
[Trick] MySQL – Order string as number
Jun 04
Database MySql, trick 3 Comments
Sometimes you have to store numbers in text format. This is not a good practice, but sometimes there is no other option.
When you perform an “order by” this field,you can get something like this:
1 2 3 4 5 6 7 8 | 1 10 11 111 12 2 20 3 |
The trick is to add a zero to you field, on the “order by” clause.
1 | select field from table order by field+0 asc |
That’s it. As simple as this