计数+每组中的和以给出每组的总和 [英] counting + sum values in each group to give total for each group

查看:121
本文介绍了计数+每组中的和以给出每组的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆