按日期类型查询LIKE

问题描述 投票:0回答:2

我正在W3School的免费数据库上执行查询,我必须执行一个查询,在该查询中打印具有year = 1996,month = 07和任何一天的所有记录。

我搜索并尝试过此表单:

SELECT Customers.Country
FROM Customers, Orders
WHERE Customers.CustomerID = Orders.CustomerID
AND (DATEPART(yy, OrderDate) = 1996
AND DATEPART(mm, OrderDate) = 07);

但是它不起作用...

我可以使用这种形式:

SELECT * 
FROM Orders 
WHERE OrderDate BETWEEN #07/15/1996# AND #07/31/1996#;

但是这仍然不知道为什么其他形式不起作用!

sql
2个回答
0
投票
SELECT Customers.Country FROM Customers, Orders WHERE Customers.CustomerID = Orders.CustomerID AND strfttime('%y', OrderDate) = 1996 AND strfttime('%m', OrderDate) = 07;

0
投票
SELECT Customers.Country FROM Customers join Orders on Customers.CustomerID = Orders.CustomerID where extract(year from OrderDate) = 1996 AND extract(month from OrderDate) = 7;
热门问题
推荐问题
最新问题