MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
astome
V2EX  ›  MySQL

关于 mysql 查询字符串排序的问题

  •  
  •   astome · Jul 24, 2016 · 3381 views
    This topic created in 3605 days ago, the information mentioned may be changed or developed.

    如果一个字段存的是

    A1 A2 A10 A15 A6 A90

    查询结果 如何倒序排序 用到什么函数吗?大神们

    6 replies    2016-07-26 17:52:29 +08:00
    lilifenghao44
        1
    lilifenghao44  
       Jul 24, 2016 via iPhone
    sql 最后加上 order by 字段名 desc
    sss3600123
        2
    sss3600123  
       Jul 24, 2016
    直接 order by 字段名
    billlee
        3
    billlee  
       Jul 24, 2016
    你是想把 A6 排在 A2 和 A10 之间吗?
    astome
        4
    astome  
    OP
       Jul 26, 2016
    @billlee 我描述的有点问题,我的意思是说如何按照 有字母后面带数字的 数据 并按照字母后面的数字大小 进行排序,如何直接 order by 会直接 把 A10 排在前面 而 A2 排后面 因为 A10 匹配的第一个数字是 1 会比 A2 大 但实际 A10 比 A2 要大
    Martin9
        5
    Martin9  
       Jul 26, 2016   ❤️ 1
    @astome
    SELECT * FROM tableName order by Cast (( substring (colname, Cast (( patindex ( ' %[0-9]% ' ,colname)) as int ), 100 )) as int )

    tablename 和 colname 对应表面和字段名
    astome
        6
    astome  
    OP
       Jul 26, 2016
    @Martin9 大牛膜拜中...
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5456 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 06:03 · PVG 14:03 · LAX 23:03 · JFK 02:03
    ♥ Do have faith in what you're doing.