给定文本/字符串列的输入,我想计算列中字符串的长度,以及每个长度的计数。
例如包含字符串的列:
'Ant'
'Cat'
'Dog'
'Human'
''
NULL
'A human'
会给出:
0 : 1
3 : 3
5 : 1
7 : 1
注意:空字符串没有算作 0 字符串,而是被忽略了。
最佳答案
length()
浮现在脑海中:
select length(col), count(*)
from t
where col is not null
group by length(col)
order by length(col);
关于string - 如何在postgresql中获取一列字符串的字符串长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47659329/