SQLite Forum

count strings with same length
Login

count strings with same length

(1) By An.Ts (Ane.Pap) on 2021-04-13 07:52:59 [source]

how can i count strings with same length in a table and pass it to another table?

(2) By anonymous on 2021-04-13 09:10:26 in reply to 1 [link] [source]

select Name, length(name), count(Name) as count from tracks WHERE length(Name) = 15

(3) By anonymous on 2021-04-13 12:10:01 in reply to 1 [link] [source]

create table t(s);
insert into t values ('a'), ('b'), ('c'), ('ab'), ('bc'), ('abc');

select length(s) len, count(s) cnt from t group by length(s);

select s,length(s) len,count(s) over (partition by length(s)) cnt from t;

The first one gives length and related count of string with that length.

The second gives each string together with the count of how many strings in the same length.

If you want to insert this output into another table just prepend (not a real work, I know) INSERT INTO table before the SELECT.

(4) By John Dennis (jdennis) on 2021-04-13 12:17:22 in reply to 1 [link] [source]

If you only want to pass how many (for example) surnames share the same length, you can do this:
select length(surname),count(surname) from df_players group by 1;

On a small database I look after, I get this:
length(surname)  count(surname)
---------------  --------------
3                52
4                252
5                524
6                660
7                558
8                396
9                211
10               97
11               40
12               11
13               5
14               6
15               2
16               1
17               1