content_image/757132.jpg content_image/757133.jpg content_image/757134.jpg content_image/757135.jpg
+----------+ | COUNT(*) | +----------+ | 9 | +----------+ 

Earlier, you retrieved the names of the people who owned pets. You can use COUNT()  if you want to find out how many pets each owner has: 

mysql> SELECT owner, COUNT(*) FROM pet GROUP BY owner; 

<img src='content_image/757132.jpg'>

The preceding query uses GROUP BY  to group all records for each owner . The use of COUNT()  in conjunction with GROUP BY  is useful for characterizing your data under various groupings. The following examples show different ways to perform animal census operations. 

Number of animals per species: 

mysql> SELECT species, COUNT(*) FROM pet GROUP BY species; 

<img src='content_image/757133.jpg'>

Number of animals per sex: 

mysql> SELECT sex, COUNT(*) FROM pet GROUP BY sex; 

<img src='content_image/757134.jpg'>

(In this output, NULL  indicates that the sex is unknown.) 

Number of animals per combination of species and sex: 

mysql> SELECT species, sex, COUNT(*) FROM pet GROUP BY species, sex; 

<img src='content_image/757135.jpg'>

