1

所以我的表有这样的记录

ID    PRODUCT      MAKE_DATE       ORDER_DATE
1       aaaa       2010-11-04      2051-12-11 16:13:43
2       bbb        2011-10-05      2010-11-11 00:00:00
3       cccc       2010-05-20      0000-00-00 00:00:00

我的问题:如何显示与2 年make_date不同的结果order_date

IM坚持这一点:

Select ID, Product, make_date, order_datetime
FROM `tbl_order`
WHERE make_date ??? order_datetime

结果应该是:

1       aaaa       2010-11-04      2051-12-11 16:13:43
3       cccc       2010-05-20      0000-00-00 00:00:00
4

2 回答 2

2
Select ID, Product, make_date, order_datetime
FROM tbl_order
WHERE make_date < order_datetime - INTERVAL 2 YEAR 
   OR make_date > order_datetime + INTERVAL 2 YEAR ;
于 2013-01-20T23:39:03.603 回答
1

对于 MySQL 使用TIMESTAMPADD函数:

SELECT ID, Product, make_date, order_datetime
FROM `tbl_order`
WHERE make_date > TIMESTAMPADD(YEAR, 2, order_datetime)
OR make_date < TIMESTAMPADD(YEAR, -2, order_datetime)
于 2013-01-20T23:25:01.167 回答