0

I have a table with names in a given column. I need to know how many names have 1 letter, how many have 2 letters, how many have 3 letters etc up to 20 letters, broken down by another column (year born).

The output needs to be something like this:

1900 1 3
1900 2 45
1900 3 453
1900 5 897
...
1900 20 2

1901 1 4
1902 2 23
..
1902 20 3

In other words for 1900 3 people have a name that is 1-char long. 45 people's names are 2 characters long. 453 people's names are 3 chars long etc.

I know it will involve length() and count but not sure how to construct it.

1 Answer 1

1

This is an aggregation query, but with a function for the aggregation:

select YearBorn, length(name) as len, count(*) as cnt
from table t
group by YearBorn, length(name)
order by YearBorn, length(name);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.