在字符串SQL中获取字符数

时间:2017-06-10 12:27:46

标签: sql

使用SQL' aaabbcdFFFFGGH'以下面的格式计数AS

A   3
B   2
C   1
D   1
F   4
G   2
H   1

3 个答案:

答案 0 :(得分:0)

this.props.navigation.navigate('AddGradeLevelScreen')

答案 1 :(得分:0)

您没有说明您的DBMS,所以这里是Postgres的解决方案:

select upper(w), count(*)
from regexp_split_to_table('aaabbcdFFFFGGH','') as t(w)
group by upper(w)
order by upper(w);

答案 2 :(得分:0)

如果是偶然的SQL Server

示例

Declare @String varchar(max) = 'aaabbcdFFFFGGH'

Select CharVal = Substring(@String,N,1)
      ,CharCnt = count(*)
 From  (Select Top (len(@String)) N=Row_Number() Over (Order By (Select NULL)) From master..spt_values N1,master..spt_values N2 ) N
 Group By Substring(@String,N,1)

<强>返回

CharVal CharCnt
a       3
b       2
c       1
d       1
F       4
G       2
H       1