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;

 

posted @ 2013-01-10 00:17  horizon~~~  阅读(2805)  评论(0编辑  收藏  举报