开发者

How to get the greatest of two columns values in MySQL?

开发者 https://www.devze.com 2022-12-10 02:21 出处:网络
I\'m trying to do something like this: SELECT MAX( ADDDATE(expirationdate, INTERVAL 1 YEAR), ADDDATE(now(), INTERVAL 1 YEAR)

I'm trying to do something like this:

SELECT MAX(
  ADDDATE(expirationdate, INTERVAL 1 YEAR),
  ADDDATE(now(), INTERVAL 1 YEAR)
)

开发者_如何学GoThat is, get "a year from now", or "a year from the expiration date stored in the table", whichever is greater (i'm renewing people's subscriptions).

This obviously doesn't work, since MAX() is for aggregation between rows, not for comparing 2 values. Is there a function that'll do this in MySQL? (i'd like to avoid doing an IF)


greatest()

0

精彩评论

暂无评论...
验证码 换一张
取 消