sql字符串排序

有一个字段内容是M0,M1,M2,M3等等

排序如下:

SELECT * from detail p WHERE p.type = 3 ORDER BY substr(p.age, 1) asc;
SELECT * from detail p WHERE p.type = 3 ORDER BY replace( p.age, ‘M’, ‘0’) asc;
SELECT * from detail p WHERE p.type = 3 ORDER BY cast(replace(p.age,’M’,”) as SIGNED INTEGER) asc;

SELECT * from detail p WHERE p.type = 3 ORDER BY FIELD(p.age,’M1′,’M2′,’M3′,’M4′,’M5′,’M6′,’M7′,’M8′,’M9′,’M10′,’M11′,’M12′,’M12+’);

    原文作者:flj924
    原文地址: https://blog.csdn.net/flj924/article/details/89401995
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞