我被要求编写一个MYSQL代码,从我的数据库中返回特定日期(仅限2003-2005年12月(的数据。但是,我无法弄清楚为什么我没有返回任何数据。我使用的代码如下。我尝试使用 BETWEEN 子句,但仍然没有返回任何数据。任何帮助将不胜感激。
select
paymentDate, amount, discounted
From
payments
where
paymentDate >= 2003-12-01 and paymentDate <= 2003-12-31
and paymentDate >= 2004-12-01 and paymentDate <= 2004-12-31
and paymentDate >= 2005-12-01 and paymentDate <= 2005-12-31
Order by paymentDate;
因为paymentDate
可能不会同时在那些年份
的十二月。而是将每个 12 月的条件语句与or
连接起来。
我还为日期添加了 ANSI 语法,即date '2003-12-01'
where
(paymentDate >= date '2003-12-01' and paymentDate <= date '2003-12-31'
or paymentDate >= date '2004-12-01' and paymentDate <= date '2004-12-31'
or paymentDate >= date '2005-12-01' and paymentDate <= date '2005-12-31')