Let's figure out how many dogs Juan has of each breed! This is the query:
SELECT breed, count(*) AS num_dogs
FROM dogs
WHERE owner = 'juan'
GROUP BY breed
ORDER BY count(*) ASC
Let's go through that query one step at a time:
owner | breed | name |
francisco | boxer | bella |
francisco | labrador | coco |
gabriela | boxer | lucy |
gabriela | boxer | lily |
juan | labrador | daisy |
alejandra | boxer | gracie |
juan | poodle | molly |
gabriela | boxer | roxy |
alejandra | terrier | maggie |
francisco | labrador | abby |
francisco | poodle | lola |
francisco | terrier | zoey |
alejandra | poodle | sophie |
juan | boxer | stella |
juan | labrador | chloe |
gabriela | labrador | zoe |
juan | boxer | sadie |
juan | terrier | ginger |
alejandra | poodle | bailey |
gabriela | boxer | penny |
owner | breed | name |
juan | labrador | daisy |
juan | poodle | molly |
juan | boxer | stella |
juan | labrador | chloe |
juan | boxer | sadie |
juan | terrier | ginger |
owner | breed | name |
juan | boxer | stella |
juan | boxer | sadie |
owner | breed | name |
juan | labrador | daisy |
juan | labrador | chloe |
owner | breed | name |
juan | poodle | molly |
owner | breed | name |
juan | terrier | ginger |
breed | num_dogs |
boxer | 2 |
labrador | 2 |
poodle | 1 |
terrier | 1 |
breed | num_dogs |
poodle | 1 |
terrier | 1 |
boxer | 2 |
labrador | 2 |