Using MySQL sort varchar column numerically with cast as unsigned when the column can begin or end with letters

后端 未结 2 633
我寻月下人不归
我寻月下人不归 2020-12-06 08:24

I\'ve ran into something I\'m not really sure how to handle here. I\'m building a database to store information on sports cards, and I\'m having a bit of an issue with some

2条回答
  •  情歌与酒
    2020-12-06 08:58

    For your sample data, you can use the length() trick:

    order by year desc, cardset asc, subset asc,
             length(cardNum),
             cardNum asc;
    

    You don't provide much sample data. This would be a general solution if, within a "subset", all the card numbers have the same form (and no leading zeros on the numeric portion).

提交回复
热议问题