Jump to content

ORDER BY customised


EchoFool

Recommended Posts

Hey,

 

I have a bunch of fields with unusual strings of numbers seperated by symbols (used for php explode stuff at later parts of my script)...

 

But i was wondering if there is a way mysql can order the data even though they are invalid integers/decimals.

 

The values are like this:

 

5:14:1+3+4+6+7

5:14:1+2+5+6+7

5:13:1+2+3+8+13

 

But i need them to order by DESC by comparing the numbers going from left to right (in a way - ignoring the : and the + symbols)How is this done?

Link to comment
https://forums.phpfreaks.com/topic/217282-order-by-customised/
Share on other sites

You would need to produce a value where the same position in each string has the same significance. That would require that every field making up the value has the same length. You could then directly compare the values as strings (even with the : and + still in them) because each character position in a string has the same significance/magnitude as that same character position in the other string(s).

 

What are the maximum number of possible digits for each number within that data? You are implying 2 (the :13, :14, and +13)

 

Edit: The short answer would be if you were to include leading zero's on each number/field making up the values when they are stored, so that each stored value has the same length/format, you could ORDER BY them directly.

 

 

Link to comment
https://forums.phpfreaks.com/topic/217282-order-by-customised/#findComment-1128321
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.