简体   繁体   English

SQL查询:按字符长度排序?

[英]SQL Query: order by length of characters?

Morning, is it possible to order sql data rows by the length of characters? 早上,是否可以按字符长度排序sql数据行?

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

I think you want to use this: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_char-length 我想你想用这个: http//dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_char-length

SELECT * FROM table ORDER BY CHAR_LENGTH(field)

You can use just simply LENGTH(), but beware, because it counts the byte number (which won't give you the expected result with multibyte strings). 你可以只使用LENGTH(),但要注意,因为它计算字节数(不会给你多字节字符串的预期结果)。

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

对于任何使用Sqlite的人

SELECT * FROM table ORDER BY LENGTH(field) DESC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM