ORDER BY “ENUM field” in MYSQL

前端 未结 5 755
忘掉有多难
忘掉有多难 2020-12-04 23:40

There is a field \'noticeBy\' enum(\'email\',\'mobile\',\'all\',\'auto\',\'nothing\') NOT NULL DEFAULT \'auto\'. As it known ordering by ENUM field performs relative to its

5条回答
  •  悲&欢浪女
    2020-12-05 00:20

    This also works:

    ORDER BY FIELD(noticeBy, 'all','auto','email','mobile','nothing')
    

    (I don't believe that there is a setting to achieve this, you have to provide the sort-values.)

提交回复
热议问题