面对Access数据库查询中的问题

时间:2013-10-09 12:31:49

标签: sql ms-access

订单表架构

enter image description here

我的访问数据库查询

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天的经销商。

但这是给出以下记录

enter image description here

我错过了什么吗?

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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天,还是今天?