Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hello everyone,
- Sorting strings and numbers in SQL.
- I have the following:
- mysql> SELECT product_article_number, product_details_size FROM product ORDER BY product_details_size;
- +------------------------+----------------------+
- | product_article_number | product_details_size |
- +------------------------+----------------------+
- | 2310104115010010R38 | 10R38 |
- | 2310104115010012R40 | 12R40 |
- | 2310104115010014R42 | 14R42 |
- | 2310104115010016R44 | 16R44 |
- | 2310104115010018R46 | 18R46 |
- | 2310104115010020R48 | 20R48 |
- | 2310104115010022R50 | 22R50 |
- | 2310104115010024R52 | 24R52 |
- | 231010411501006R34 | 6R34 |
- | 231010411501008R36 | 8R36 |
- +------------------------+----------------------+
- And as you can see it is not sorted correctly.
- What i' m looking for is the following:
- +------------------------+----------------------+
- | product_article_number | product_details_size |
- +------------------------+----------------------+
- | 231010411501006R34 | 6R34 |
- | 231010411501008R36 | 8R36 |
- | 2310104115010010R38 | 10R38 |
- | 2310104115010012R40 | 12R40 |
- | 2310104115010014R42 | 14R42 |
- | 2310104115010016R44 | 16R44 |
- | 2310104115010018R46 | 18R46 |
- | 2310104115010020R48 | 20R48 |
- | 2310104115010022R50 | 22R50 |
- | 2310104115010024R52 | 24R52 |
- +------------------------+----------------------+
- Maybe with the function LPAD ? But I cant isolate the first digits.
- Any idea.
- Maybe with Regex to take out the digit and perform LPAD?
- And ofcourse, i don' t want to use an index table ;)
- Kind regards,
- Django
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement