gpt4 book ai didi

SQL 查询 Access - 显示截至 9 月底的记录

转载 作者:行者123 更新时间:2023-12-04 21:04:38 24 4
gpt4 key购买 nike

我不确定如何显示到 9 月底的记录。

到目前为止,我的代码似乎因错误“条件表达式中的数据类型不匹配”而失败。

SELECT Month(InvoiceDate) AS IncomeMonth, Sum(TotalPrice) AS Income
FROM INVOICE
WHERE InvoiceDate <= '30/9/2018'
GROUP BY Month(InvoiceDate);

示例数据:

InvoiceDate | TotalPrice
05/11/18 | $200
05/04/18 | $100
05/05/18 | $150
05/03/18 | $120
05/07/18 | $100

预期输出查询结果:

IncomeMonth | Income
4 | $100
6 | $150
3 | $120
7 | $100
3 | $120
7 | $100

最佳答案

因为您可能希望在下个月运行类似的查询,所以将其设为动态:

SELECT 
Month(InvoiceDate) AS IncomeMonth, Sum(TotalPrice) AS Income
FROM
INVOICE
WHERE
InvoiceDate < DateSerial(Year(Date()), Month(Date()), 1)
GROUP BY
Month(InvoiceDate);

关于SQL 查询 Access - 显示截至 9 月底的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52732817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com