【发布时间】:2021-10-20 22:30:48
【问题描述】:
假设我有一个人的表,其 id 和名称如下
[Person]
ID NAME
================
1 Michael
2 Michelle
3 Emma
4 Evan
5 Ellen
6 Gary
我想根据他们名字的第一个字符来计算人数。 这是我期望的输出
NUMBER_OF_PERSONS
=================
2 //M = Michael and Michelle
3 //E = Emma, Evan and Ellen
1 //G = Gary
如何在 Oracle 中实现这一点?
这是我的查询
select count(id) as number_of_person
from person
where substr(name) in (select distinct substr(name,1,1) from person);
【问题讨论】: