Ishu Bhardwaj Ishu Bhardwaj - 7 months ago 11
SQL Question

MySql Query To Find Sum Of Repeat Count

I have a table which looks like:

Name
A
A
A
A
B
B
B
B
C
C
D
E
F
F
F
G


On above table if I try to execute following repeat query:

select Name as Name,count(Name) as Repeat_Count
from call_data
GROUP BY 1
HAVING (Repeat_Count > 1);


My result coming as:

Name Repeat_Count
A 4
B 4
C 2
D 1
E 1
F 3
G 1


However I want your guys help to get sum of Repeat_Count column.....as per above sample my output will be 16

It will be great if anyone can share a query to execute what I am looking for.

Thanks

Answer
select name,sum(repeat_count) from
(select Name as Name,count(Name) as Repeat_Count
    from call_data 
    GROUP BY 1  
HAVING (Repeat_Count > 1))temp;

Will return 16 for all records in name column is this what you want ?

Comments