MySQL:按字段大小/长度sorting

这是一个表结构(例如testing):

__________________________________________ | Field Name | Data Type | |________________|_________________________| | id | BIGINT (20) | |________________|_________________________| | title | varchar(25) | |________________|_________________________| | description | text | |________________|_________________________| 

一个查询如:

 SELECT * FROM TEST ORDER BY description DESC; 

但是我想按字段大小/字段长度来sorting。 字段types将是TEXT或BLOB。

 SELECT * FROM TEST ORDER BY LENGTH(description) DESC; 

LENGTH函数以字节为单位给出了string的长度。 如果要计算(多字节)字符,请改用CHAR_LENGTH函数:

 SELECT * FROM TEST ORDER BY CHAR_LENGTH(description) DESC; 
 SELECT * FROM TEST ORDER BY CHAR_LENGTH(description); 

对于那些使用MS SQL

 SELECT * FROM TEST ORDER BY LEN(field)