2017-02-15 52 views

回答

4

你必須先從較低的值使用between

select * 
from table 
WHERE date BETWEEN NOW() - INTERVAL 10 DAY and NOW() 
ORDER BY date 
0

的問題時,不相關的NOW()本功能離子但對BETWEEN操作,下時間戳必須首先規定:

where date between now() - interval 10 day and now() 

然而,根據您的要求,您可能希望使用此:

where date between current_date() - interval 10 day and current_date() 

或只是

where date>=current_date() - interval 10 day 

now()返回一個包含日期和時間信息的timestamp,而current_date()僅返回當前日期而不用添加電子信息。如果日期只是一個date列,沒有時間信息,則使用now() - interval 10 day,您將得到最新的9天,而不是您預期的最新的10天。