本文介绍了SQL / MySQL - 按列长度排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在MySQL中,有没有办法按照列的长度(字符)来排序结果?
例如:
myColumn
________________
lor
lorem
lorem ip
lorem ips
lorem ipsum
我想按照最小列长度lor最大列长度,lorem ipsum。
解决方案任何建议都可以收到... / div>
您可以使用 功能:
ORDER BY CHAR_LENGTH(column)
注意 CHAR_LENGTH c $ c>也适用于Unicode字符串,其中
LENGTH()
适用于拉丁文,但可能会给出意想不到的Unicode结果:
In MySQL, is there a way to order my results by the length (characters) of a column?
For example:
myColumn
________________
lor
lorem
lorem ip
lorem ips
lorem ipsum
I would like to order my results by the smallest column length first, "lor", and ending in the largest column length, "lorem ipsum". This should include column lengths of 0 too.
Any suggestions gratefully received...
解决方案
You can use CHAR_LENGTH()
function:
ORDER BY CHAR_LENGTH( column )
Notice that CHAR_LENGTH()
works for Unicode strings as well, where LENGTH()
is OK for Latin but may give unexpected results with Unicode:
这篇关于SQL / MySQL - 按列长度排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-13 17:10