表格:
id actor result
1 Aman 20
2 Aman 23
3 Ston 21
4 halazon 21
5 klawi 20
6 halazon 14
我想按第一个字母查询参与者,以及他们在表中的次数我尝试过,但没有成功:
查询:
select actor, count(*) from actors
where actor = (select actor from actors
where actor like 'A%' GROUP by actor order by actor ASC)
预期结果:
Aman 2
我看不出子查询有什么意义-此外,如果多个参与者的名称以a开头,它将失败(子查询将返回多行,不能与=
一起使用(。
如果你认为你想要直接过滤:
select actor, count(*) as cnt
from actors
where actor like 'A%'
group by actor
order by actor