访问,按月汇总一周中每一天的总和
Access, Aggregate sums for each day of the week on a monthly basis
我试图按月计算一周中每一天的销售总额。我相信 Access 中的工作日功能可用于执行此操作。下面查询中的 Weekday 函数代码不起作用。应如何修改 Weekday 函数语法以便对一周中每一天的销售总额求和? (下面的查询已更新为正确的代码,return 将得到正确的结果。)
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;
您似乎没有使用 weekday 函数对参数进行实际比较:
对于每个工作日比较,尝试更改
weekday(date_value = #))
至此
EDIT-change to remove popup and use actual field
weekday(sale_date) = #)
我试图按月计算一周中每一天的销售总额。我相信 Access 中的工作日功能可用于执行此操作。下面查询中的 Weekday 函数代码不起作用。应如何修改 Weekday 函数语法以便对一周中每一天的销售总额求和? (下面的查询已更新为正确的代码,return 将得到正确的结果。)
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;
您似乎没有使用 weekday 函数对参数进行实际比较:
对于每个工作日比较,尝试更改
weekday(date_value = #))
至此
EDIT-change to remove popup and use actual field
weekday(sale_date) = #)