This is my table for a mysql database. http://the44.simorasic.com/cages.html
I need to show the number of cages for each cage size, along with the total expenditure (cost) in purchasing the cages of that size. Also, to show only the cage size, count of cages and total cost of cages.
What I have so far is this,
SELECT cageSize, COUNT(*) as "Number of cages"
from cage
GROUP BY cageSize;
So I have managed to count them, but the tricky part is adding the values together for each size, and then giving a total value for each size. Please help as this is part of my assignment, and I am completely stuck. I know I have to create a group for each size, and then sum the values, but can’t manage to do so.
What you are looking for can be found here:
Group By aggregate functions
Plus you will need the “WITH ROLLUP” keyword for getting the total.
Group By modifiers