简体   繁体   中英

SQL MAX datetime - 1 day

I want to do a comparison between two dates. The highest date (currently via MAX datetime) is working, but I can't get the day after the highest date to compare the data with.

I'm using the following to get the data of the highest available date:

SELECT `datetime`, `standardSubscriptionDuration`,
SUM(`activeStandardPriceSubscriptions`) AS OneMonthActiveStandard
FROM `Subscription_totals`
WHERE `standardSubscriptionDuration` = '1 Month'
AND `datetime` = (SELECT MAX(`datetime`) AS Date FROM `Subscription_totals`)";

I already tried:

(SELECT MAX(`datetime`) -1 AS Date

But this won't give the result. How am I able to get the data of yesterday and eventually compare them?

I think that you want the following date arithmetics:

WHERE 
    `standardSubscriptionDuration` = '1 Month' 
    AND `datetime` = (
            SELECT MAX(`datetime`) - interval 1 day AS Date FROM `Subscription_totals`
    )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM