How to get the number of unique string lengths in database rows?

I am using Oracle and I have a table with 1000 rows. There is a last name field and

I want to know the length of the name field, but I do not want it for each line. I want to count different lengths.

Example:

Lastname:

smith smith Johnson Johnson Jackson Baggins 

There are two five blacksmiths. Four others, length seven. I want my request to be returned

 7 5 

If there were 1000 names, I expected to get all kinds of lengths.

I tried,

 Select count(*) as total, lastname from myNames group by total 

He did not know how much there was. Grouping by name always groups by each individual name, unless another surname is true, but not true to me.

Can this be done in a single SQL query?

+4
source share
2 answers
 SELECT Length(lastname) FROM MyTable GROUP BY Length(lastname) 
+5
source
 select distinct(LENGTH(lastname)) from mynames; 
+6
source

Source: https://habr.com/ru/post/1381926/


All Articles