I need some help in creating a MySQL query. Let's assume we have a table "animals" containing the species and also the detailed breed of animals. Furthermore we have a table "examinations" containing investigations on animals. To find out how many animals there are of certain breeds that were examined (we're not interested in finding out how many examinations occured on certain breeds!), we could run this query:
SELECT animals.animal_species,
animals.animal_breed,
Count(DISTINCT animals.animal_id)
FROM examinations,
animals
WHERE examinations.examination_animal_id = animals.animal_id
AND animals.animal_breed IS NOT NULL
GROUP BY animals.animal_species,
animals.animal_breed
ORDER BY animals.animal_species
By running this we get something like:
dog | sheepdog | 3
dog | collie | 1
dog | terrier | 5
cat | Persian cat | 3
cat | Birman cat | 2
Now I want to include a total sum of each species. The result should look like this:
dog | sheepdog | 3 | 9
dog | collie | 1 | 9
dog | terrier | 5 | 9
cat | Persian cat | 3 | 5
cat | Birman cat | 2 | 5
Can you please tell me how I have to change my query to achieve this? I tried several solutions, but none of them worked ...
Thank you so very much in advance!