计数+每组中的和以给出每组的总和 [英] counting + sum values in each group to give total for each group
问题描述
这是我的mysql数据库表。 http://the44.simorasic.com/cages.html
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.
推荐答案
此外,您还需要WITH ROLLUP
Plus you will need the "WITH ROLLUP" keyword for getting the total.
这篇关于计数+每组中的和以给出每组的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!