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

前端 未结 4 2024
故里飘歌
故里飘歌 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 03:03

    You can use LEAST and GREATEST function to achieve it.

    SELECT
        GREATEST(A.date0, B.date0) AS date0,
        LEAST(A.date1, B.date1) AS date1
    FROM A, B
    WHERE B.x = A.x
    

    Both are described here http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html

提交回复
热议问题