您要为每个字符创建一个单独的行。一种方法是生成所有字符,然后由它们聚合。这是一种方法:
select chr(chars.c + ascii('A')) as c, sum(case when ascii(left(m.nome, 1)) = chars.c + ascii('A') then 1 else 0 end)from generate_series(0, 25) as chars(c) cross join merchant mgroup by c;
编辑:
艾伦的建议是一个更好的查询:
select chr(chars.c + ascii('A')) as c, count(m.nome)from generate_series(0, 25) as chars(c) left join merchant m on ascii(left(m.nome, 1)) = chars.c + ascii('A')group by c;
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)