MySQL:按字段大小/长度排序 [英] MySQL: Order by field size/length
本文介绍了MySQL:按字段大小/长度排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个表格结构(例如测试):
Here is a table structure (e.g. test):
__________________________________________
| Field Name | Data Type |
|________________|_________________________|
| id | BIGINT (20) |
|________________|_________________________|
| title | varchar(25) |
|________________|_________________________|
| description | text |
|________________|_________________________|
查询,例如:
SELECT * FROM TEST ORDER BY description DESC;
但是我想按字段说明的字段大小/长度进行排序.字段类型将为TEXT或BLOB.
But I would like to order by the field size/length of the field description. The field type will be TEXT or BLOB.
推荐答案
SELECT * FROM TEST ORDER BY LENGTH(description) DESC;
LENGTH
函数提供字符串的长度(以字节为单位).如果要计算(多字节)字符,请使用
The LENGTH
function gives the length of string in bytes. If you want to count (multi-byte) characters, use the CHAR_LENGTH
function instead:
SELECT * FROM TEST ORDER BY CHAR_LENGTH(description) DESC;
这篇关于MySQL:按字段大小/长度排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文