how can I order like this in mysql [closed]
How can I order in mysql like
1 1/2 2 3/1 3/2 3/12 5 5/1 7 13/1
when i or der it bring 1 1/2 13/1 befor 5
format is x/x whre x is number
I think you need to split the column into two separate columns. I'm by no means a MySQL expert, you may have to wrap this inside a subselect or otherwise manipulate it, and as we've discussed, you'll need to convert these from strings into integers (I can't seem to make this work on the MySQL install I've got, but I never use it):
select
SUBSTRING_INDEX(a,'/',1) as PartA,
CASE WHEN LOCATE('/',a) > 0 THEN SUBSTRING_INDEX(a,'/',-1) ELSE '0' END as PartB
from
<rest of query>
Where a
is the name of this column. Like I say, I can't seem to fathom MySQLs syntax for converting these values into integers, and also, obviously, we then need to apply an ORDER BY clause.
Sorry this is an incomplete answer, but hopefully it will point you in the right direction, and no-one else seems to be answering...
Based on what I've just seen in your comment, I think we can get them numeric by:
select
CAST(SUBSTRING_INDEX(a,'/',1) as decimal) as PartA,
CAST(CASE WHEN LOCATE('/',a) > 0 THEN SUBSTRING_INDEX(a,'/',-1) ELSE '0' END as decimal) as PartB
from
<rest of query>
精彩评论