如何使用自定义排序方法对数据进行 MySQL 排序?
How can I make MySQL sort data using a custom sorting method?
我有
SELECT revision
FROM table
WHERE id = 4
ORDER BY revision DESC
LIMIT 1;
暂时忽略限制子句,结果如下:
Returns | I want
--------------------
Z | AD //with LIMIT clause this is what's returned
//& what I seek is the first row
//provided it's sorted properly
Y | AC
X | AB
W | AA
.... | Z
B | Y
A | X
AD | ....
AC | C
AB | B
AA | A
MySQL可以做到吗?
我的目标是按照上面的方式对数据进行排序。数据进入 PHP,我可以在其中重新排序,但我很好奇是否可以直接从 MySQL.
执行此操作
按字符长度 desc 排序,然后按字母排序。
SELECT revision
FROM table
WHERE id = 4
ORDER BY CHAR_LENGTH(revision) DESC,
revision DESC
LIMIT 1;
我有
SELECT revision
FROM table
WHERE id = 4
ORDER BY revision DESC
LIMIT 1;
暂时忽略限制子句,结果如下:
Returns | I want
--------------------
Z | AD //with LIMIT clause this is what's returned
//& what I seek is the first row
//provided it's sorted properly
Y | AC
X | AB
W | AA
.... | Z
B | Y
A | X
AD | ....
AC | C
AB | B
AA | A
MySQL可以做到吗?
我的目标是按照上面的方式对数据进行排序。数据进入 PHP,我可以在其中重新排序,但我很好奇是否可以直接从 MySQL.
执行此操作按字符长度 desc 排序,然后按字母排序。
SELECT revision
FROM table
WHERE id = 4
ORDER BY CHAR_LENGTH(revision) DESC,
revision DESC
LIMIT 1;