早上,是否可以按字符长度排序sql数据行?
e.g。 SELECT * FROM database ORDER BY data.length()
答案 0 :(得分:67)
我想你想用这个:http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_char-length
SELECT * FROM table ORDER BY CHAR_LENGTH(field)
你可以只使用LENGTH(),但要注意,因为它计算字节数(不会给你带有多字节字符串的预期结果)。
答案 1 :(得分:36)
SELECT * FROM database ORDER BY Len(data)
答案 2 :(得分:8)
SELECT * FROM table ORDER BY length(data) desc
数据是varchar字段
答案 3 :(得分:1)
SELECT * FROM YourTable ORDER BY LENGTH(Column_Name) DESC
e.g;
SELECT * FROM Customer ORDER BY LENGTH(CustomerName) DESC
答案 4 :(得分:1)
任何使用 Sqlite
的人SELECT * FROM table ORDER BY LENGTH(field) DESC