2012-01-10 139 views
2

什麼是MySQL查詢來計算包含相同值的行總數。 例如:計數包含相同值的行數

考慮包含所有動物名稱的表animal。如果表中有5行包含值name'cow'那麼對它的查詢會是什麼?

回答

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