简体   繁体   English

SQL MAX 日期时间 - 1 天

[英]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.最高日期(目前通过 MAX datetime)正在工作,但我无法在最高日期之后的第二天与数据进行比较。

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`
    )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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