MySQL Select minimum/maximum among two (or more) given values

前端 未结 4 2020
故里飘歌
故里飘歌 2020-12-01 02:22

Is it possible to SELECT the minimum or maximum among two or more values. I\'d need something like this:

SELECT MAX_VALUE(A.date0, B.date0) AS d         


        
4条回答
  •  盖世英雄少女心
    2020-12-01 02:59

    Just watch out if NULL is likely to be in a field value ...

    SELECT LEAST(NULL,NOW());
    

    and

    SELECT GREATEST(NULL,NOW());
    

    both return null, which may not be what you want (especially in the case of GREATEST)

提交回复
热议问题