【发布时间】:2016-07-16 15:23:23
【问题描述】:
我正在尝试按月汇总一周中每一天的销售总额。我相信 Access 中的 Weekday 功能可用于执行此操作。下面查询中的 Weekday 函数代码不起作用。应该如何修改 Weekday 函数语法以便对一周中的每一天的销售总额求和? (下面的查询已经更新了正确的代码,将返回正确的结果。)
SELECT Format(DatePart("m",months.month_start),"00") & "/" & Year(months.month_start) AS [Month/Year],
(SELECT Round(Nz(Sum(sales_receipt.SELLING_PRICE*sales_receipt.quantity),0),2)
FROM SALES_RECEIPT
WHERE SALES_RECEIPT.SALE_DATE between months.month_start and months.month_end and weekday(sale_date) = 1) AS [Sunday Sales Total],
(SELECT Round(Nz(Sum(sales_receipt.SELLING_PRICE*sales_receipt.quantity),0),2)
FROM SALES_RECEIPT
WHERE SALES_RECEIPT.SALE_DATE between months.month_start and months.month_end and weekday(sale_date) = 2) AS [Monday Sales Total],
(SELECT Round(Nz(Sum(sales_receipt.SELLING_PRICE*sales_receipt.quantity),0),2)
FROM SALES_RECEIPT
WHERE SALES_RECEIPT.SALE_DATE between months.month_start and months.month_end and weekday(sale_date) = 3) AS [Tuesday Sales Total],
(SELECT Round(Nz(Sum(sales_receipt.SELLING_PRICE*sales_receipt.quantity),0),2)
FROM SALES_RECEIPT
WHERE SALES_RECEIPT.SALE_DATE between months.month_start and months.month_end and weekday(sale_date) = 4) AS [Wednesday Sales Total],
(SELECT Round(Nz(Sum(sales_receipt.SELLING_PRICE*sales_receipt.quantity),0),2)
FROM SALES_RECEIPT
WHERE SALES_RECEIPT.SALE_DATE between months.month_start and months.month_end and weekday(sale_date) = 5) AS [Thursday Sales Total],
(SELECT Round(Nz(Sum(sales_receipt.SELLING_PRICE*sales_receipt.quantity),0),2)
FROM SALES_RECEIPT
WHERE SALES_RECEIPT.SALE_DATE between months.month_start and months.month_end and weekday(sale_date) = 6) AS [Friday Sales Total],
(SELECT Round(Nz(Sum(sales_receipt.SELLING_PRICE*sales_receipt.quantity),0),2)
FROM SALES_RECEIPT
WHERE SALES_RECEIPT.SALE_DATE between months.month_start and months.month_end and weekday(sale_date) = 7) AS [Saturday Sales Total]
FROM (SELECT DateSerial(Year(sale_date), Month(sale_date), 1) AS month_start,
DateAdd("d", -1, DateSerial(Year(sale_date), Month(sale_date) + 1, 1)) AS month_end
FROM SALES_RECEIPT
WHERE sale_date between #1/1# And #12/31#
GROUP BY Year(sale_date), Month(sale_date)) AS months;
【问题讨论】:
-
解释“它不起作用”的症状。您希望它的外观和实际结果的示例数据集
-
运行查询时,会出现一个“ENTER PARAMETER VALUE”框,询问“date_value”。如果我输入的 date_value 为 1,即星期日,则 1 月份一周中的每一天的价值为 2016.62 美元(2016.62 美元是 1 月份所有 31 天的销售额)。周日应该是 0 美元,因为商店周日不营业。除周日外,每一天的收入应少于 2016.62 美元,但 1 月份一周中每一天的总和应为 2016.62 美元。
标签: ms-access-2010 aggregate-functions weekday