Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Table:

id  actor   result
1   Aman    20
2   Aman    23
3   Ston    21
4   halazon 21
5   klawi   20
6   halazon 14

I want to query actors by first letter and how many times they are in the table I tried this but no success:

Query:

select actor, count(*) from actors 
where actor = (select actor from actors
where actor like 'A%' GROUP by actor order by actor ASC)

Expected Result:

Aman 2

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
560 views
Welcome To Ask or Share your Answers For Others

1 Answer

I don't see the point for a subquery - plus, it will fail if more than one actor has a name that starts with an A (the subquery will return more than one row, which cannot be used along with =).

If think you want direct filtering:

select actor, count(*) as cnt
from actors 
where actor like 'A%' 
group by actor 
order by actor

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share

548k questions

547k answers

4 comments

56.5k users

...