且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySql如何在Between子句中使用DATE_SUB

更新时间:2023-01-19 17:16:00

我不确定您遇到什么错误,但这将无法正常工作.原因是您的 BETWEEN 子句中的参数被颠倒了. BETWEEN 要求第一个参数是min,第二个参数是最大 DATE_SUB 将从日期中减去间隔提供了使其小于当前日期的功能.

I am not sure what error you are getting, but this will not work. The reason is that the arguments in your BETWEEN clause are reversed. BETWEEN requires the first argument to be the min and the second to be the max. DATE_SUB will subtract the interval from the date provided making it less than the current date.

尝试这样的事情:

SELECT
    * 
FROM 
    SellBySalesman 
WHERE 
    userid=37 and 
    sellingDate BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND CURDATE()