[英]access-sql and VBA: SUM current month and year(february/2017) AND current month and last year (february/2016)
我想在Access中创建一个表单,该表单应该总结当前月份和年份以及当前月份和去年的产品销售数量。
结果应如下所示:
ProductID,Sales16,Sales17
我该怎么办? 因此,我每个月都会自动获得所需的结果,只需单击Access工具中的按钮即可。 也许将vba代码与SQL查询结合起来?
给定字段:productid,dateofsale(dd:mm:yyyy),numberofsale,...
我很感激每个帮助,提示,...
感谢你 ! :)
虽然您可以沿着这条路走下去,但为什么不使用访问报告呢? 它将从任何查询或表中对您的数据进行分组和汇总。
表格应该用于输入和编辑数据。 报告应用于显示数据库中的报告。 这将为您节省很多麻烦,根据您的简单要求,您可能不需要任何代码。
您可以使用此查询:
Select
productid,
Sum(IIf(dateofsale Between
DateSerial(Year(Date()), Month(Date()), 1) And
DateSerial(Year(Date()), Month(Date()) + 1, 0), numberofsale, 0)) As
totalthis,
Sum(IIf(dateofsale Between
DateSerial(Year(Date()) - 1, Month(Date()), 1) And
DateSerial(Year(Date()) - 1, Month(Date()) + 1, 0), numberofsale, 0)) As
totallast
From
YourTable
Group By
productid
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.