简体   繁体   中英

Count number of rows which contains same value

What is the MySQL query to count the total number of rows which contains the same value. For example:

Consider a table animal which contains all animal names. If there are 5 rows in the table which contains the value name as 'cow' then what would be the query for it?

SELECT animal_name,
       COUNT(*) AS animal_count
FROM   animal_table
GROUP  BY animal_name;  
SELECT name, COUNT(*) c FROM animal WHERE name='cow' GROUP BY name
SELECT COUNT(*) AS CowCount 
FROM tableName
where animalName = 'cow';

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