SQL文中取两个字段的最小值

方法1:

select min(c) from 
(select  min(b) as c from tab_name
union
select min(a) as c from tab_name);

方法2:

select least(min(A),min(B)) from table;
least(...),greatest(...)中如果含有null的话,无法得到结果
select greatest(max(A),max(B)) from table;

 

你可能感兴趣的:(sql)