如何对另一列的分组中的一列求和? [英] How do I sum one column within a grouping of another column?

查看:80
本文介绍了如何对另一列的分组中的一列求和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题:

NAME    DATE           PRESENTS
bob     march 3 2011      1
bob     june 6 2008       2
bob     jan 3 2012        3
mary    feb 14 1986       4
mary    april 10 2001     5
mary    jan 3 2012        6
kate    march 3 2011      7
kate    jan 3 2012        8
kate    oct 9 2013        9
celia   march 3 2011     10
celia   feb 14 1986      11
celia   july 4 2011      12
celia   jan 3 2012       13
celia   feb 14 1991      14

因此,目标是,如果凯特和西莉亚当天收到的礼物全都计入,则我们将它们加在一起.

So the goal is that we add the amount of presents Kate and Celia got on the same days if they received any at all on those days.

除了需要更大的数据集外,我需要做的是这样的.数据集的大小可能约为100,000个条目.

What I need to do is kind of like this, except with a much bigger data set. The size of the data set is probably around 100,000 entries.

我需要用SQL或Access 2003查询作为答案.

I need the answer in SQL, or as an Access 2003 query.

推荐答案

如果presents是在特定日期出现的凯特或西莉亚或其他某人的礼物数量:

If presents is the number of presents kate or celia or somepne else got on a particular date:

select name, date, sum(presents) total_on_date
from table
where name in ('kate','celia')
group by name, date

我绝对不是SQL天才

这篇关于如何对另一列的分组中的一列求和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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