简体   繁体   English

通过SQL查询或VBA对多列MS访问进行求和

[英]Sum Multiple Column MS Access Via Sql Query or VBA

Problem:I am trying to make a Inventory Management Database on Microsoft Access 2010, and since i needed records date wise my Table looks like follows 问题:我正在尝试在Microsoft Access 2010上建立库存管理数据库,并且由于我需要明智地记录日期,因此我的表如下所示

 SKU   2016-03-16   2016-03-17   2016-03-18   ...   Total
 AAA   10           -5           15           ...   20
 BBB   05           05           25           ...   35
 CCC   06           -5           24           ...   25

This way i wanted to add records for each day, but i am unable to make a "Total" column which will total all the columns (Sum(Columns*)) 这样我想每天添加记录,但是我无法创建一个“总计”列,该列将总计所有列(Sum(Columns *))

I am aware of sum and groupby but that works across multiple rows i am looking for something which can do the same for column 我知道sum和groupby,但是它可以跨多行工作,我正在寻找可以对列执行相同操作的东西

Expected Solution: A way either by Sql Query or VBA to total all the columns for SKU AAA,BBB,CCC, if not possible to total in the same table then i am open to total the columns in a new table. 预期的解决方案:一种方法是通过Sql Query或VBA总计SKU AAA,BBB,CCC的所有列,如果不可能总计在同一张表中,则我愿意在新表中总计列。

Such a table is normally result of pivoting summary data. 该表通常是透视汇总数据的结果。 Real data would look like: 实际数据如下所示:

SKU, Date, Quantity ... SKU,日期,数量...

Then probably you would want to create a PIVOT table using SKU for rows, Date for Columns and Quantity for data (default operation is SUM). 然后,您可能想使用SKU创建PIVOT表,将行用作SKU,将日期用作列,将数据用作数量(默认操作为SUM)。 It would have the row totals by default. 默认情况下它将具有行总数。 It may have been named crosstab, cross tab .. or so in Access 2010. 在Access 2010中,它可能已被命名为crosstab,cross tab ..等等。

(you may want to do the pivoting in Excel) (您可能想在Excel中进行透视)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM