SQL查询:按字符长度sorting?

早上,有可能按字符长度sortingsql数据行吗?

例如SELECT * FROM database ORDER BY data.length()

我想你想用这个: http : //dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_char-length

 SELECT * FROM table ORDER BY CHAR_LENGTH(field) 

你可以只使用LENGTH(),但要小心,因为它计算字节数(这不会给你多字节string的预期结果)。

 SELECT * FROM database ORDER BY Len(data) 
 SELECT * FROM table ORDER BY length(data) desc 

数据是varchar字段

 SELECT * FROM YourTable ORDER BY LENGTH(Column_Name) DESC 

例如;

 SELECT * FROM Customer ORDER BY LENGTH(CustomerName) DESC