MySQL ORDER BY [自定义SET字段值] [英] MySQL ORDER BY [custom SET field value]

查看:336
本文介绍了MySQL ORDER BY [自定义SET字段值]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望对此有一个简单的解决方案:

I hope there's a simple solution for this:

我有一个表,其中每一行都有其自己的状态(SET类型字段).状态可以是:

I have a table where each row has it's own status (SET type field). Statuses can be:

  • 离线
  • 可用
  • 距离

我想按以下顺序订购

  • 可用
  • 距离
  • 离线

我觉得很简单

ORDER BY `status` ASC

可以解决问题(按字母顺序),但是它给了我以下内容:

will do the trick (alphabetical order) but it gives me the following:

  • 离线
  • 可用
  • 距离

如何以最简单的方式解决这个问题?

How can is sort out this in the most simple way?

预先感谢

fabrik

推荐答案

我想添加另一种通过自定义字段值进行排序的方法,

Thought I'd add another way to order by custom field values,

ORDER BY FIND_IN_SET(status, 'available,busy,distance,offline')

(如果给定的字符串包含引号,则只需将其转义)

(If the given strings contain a quote simply escape it)

这篇关于MySQL ORDER BY [自定义SET字段值]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆