1

订单表架构

在此处输入图像描述

我的 Access 数据库查询

Select * from 
(
     SELECT reseller.id, Max(orders.[order date]) as OrderDate
     FROM Reseller INNER JOIN orders ON Reseller.ID = orders.ResellerID
     group by reseller.id
)K
WHERE (((K.[OrderDate]) Not Between (Date()-1) And (Date()-18)))

找到那些 18 天没有订购的经销商。

但这给出了以下记录

在此处输入图像描述

我错过了什么吗?

4

2 回答 2

2

试试这个查询:

SELECT * 
FROM 
    (
        SELECT reseller.id, Max(orders.[order date]) AS OrderDate
        FROM 
            Reseller 
            INNER JOIN 
            orders 
                ON Reseller.ID = orders.ResellerID
        GROUP BY reseller.id
    ) K
WHERE DateDiff("d", K.[OrderDate], Date()) > 18
于 2013-10-09T12:58:50.973 回答
1

尝试这个

Select * from 
(
     SELECT reseller.id, Max(orders.[order date]) as OrderDate
     FROM Reseller INNER JOIN orders ON Reseller.ID = orders.ResellerID
     group by reseller.id
)
WHERE (((K.[OrderDate]) Not Between (    DateAdd("d", -1, Date()) 
                                     And DateAdd("d", -18, Date())
                                    )

认为当您执行 Date() - 1 时,它会在内部减去 1 次,直到从日期中减去秒的子部分,而不是您打算减去 1 个日期

此外,没有改变,但您真的想在今天达到最高限制 - 1 天,还是就在今天?

于 2013-10-09T12:49:15.620 回答