Advertisement
DjAngo23

Mysql Complex Sort

Feb 15th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. Hello everyone,
  2.  
  3. Sorting strings and numbers in SQL.
  4. I have the following:
  5.  
  6. mysql> SELECT product_article_number, product_details_size FROM product ORDER BY product_details_size;
  7. +------------------------+----------------------+
  8. | product_article_number | product_details_size |
  9. +------------------------+----------------------+
  10. | 2310104115010010R38 | 10R38 |
  11. | 2310104115010012R40 | 12R40 |
  12. | 2310104115010014R42 | 14R42 |
  13. | 2310104115010016R44 | 16R44 |
  14. | 2310104115010018R46 | 18R46 |
  15. | 2310104115010020R48 | 20R48 |
  16. | 2310104115010022R50 | 22R50 |
  17. | 2310104115010024R52 | 24R52 |
  18. | 231010411501006R34 | 6R34 |
  19. | 231010411501008R36 | 8R36 |
  20. +------------------------+----------------------+
  21.  
  22. And as you can see it is not sorted correctly.
  23. What i' m looking for is the following:
  24.  
  25. +------------------------+----------------------+
  26. | product_article_number | product_details_size |
  27. +------------------------+----------------------+
  28. | 231010411501006R34 | 6R34 |
  29. | 231010411501008R36 | 8R36 |
  30. | 2310104115010010R38 | 10R38 |
  31. | 2310104115010012R40 | 12R40 |
  32. | 2310104115010014R42 | 14R42 |
  33. | 2310104115010016R44 | 16R44 |
  34. | 2310104115010018R46 | 18R46 |
  35. | 2310104115010020R48 | 20R48 |
  36. | 2310104115010022R50 | 22R50 |
  37. | 2310104115010024R52 | 24R52 |
  38. +------------------------+----------------------+
  39.  
  40. Maybe with the function LPAD ? But I cant isolate the first digits.
  41. Any idea.
  42. Maybe with Regex to take out the digit and perform LPAD?
  43. And ofcourse, i don' t want to use an index table ;)
  44.  
  45. Kind regards,
  46. Django
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement