简体   繁体   中英

count repeated value in table field

how i can count the repeated value in any field of mysql db's table.

Example:

    id name
    1  aaa
    2  aaa
    3  ttt
    4  ccc
    5  ttt
    6  ccc
    7  aaa
    8  zzz

How i can get how many times value is repeated in table like.

    aaa =3 times in table
    ttt =2 times in table
    ccc =2 times in table
    zzz =1 times in table

I think it possible with count of the mysql but how to use it i dont know any one can help ?please answer ma question thanks in adv.

You need to group by your name column and then you can use an aggregate function like count() on that group

select name, count(id)
from your_table
group by name

Write below query to get count of each name

select name, count(name)
from your_table
group by name

OR to get count of specific name

select name, count(name)
from your_table
where name = "aaa"
group by name 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM