MySQL在两个(或多个)给定值中选择最小值/最大值


Answers:




9

只要注意是否在字段值中可能存在NULL ...

SELECT LEAST(NULL,NOW());

SELECT GREATEST(NULL,NOW());

都返回null,这可能不是您想要的(特别是在GREATEST的情况下)


2

试试这个:

SELECT GREATEST(A.date0, B.date0) AS `date0`,LEAST(A.date0, B.date0) AS `date1`
  FROM A 
  JOIN  B
    ON A.id = B.role;
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.