57,064
社区成员
发帖
与我相关
我的任务
分享alter table tab1 add minVal int as (least(if( a>0, a ,100000000),if(b>0,b,100000000),if(c>0,c,100000000),if(d>0,d,100000000)) ) ;
create index IDX_tab1_minVal on tab1(minVal);
select a,b,c,d,if(minVal=100000000,null,minVal) as minVal from tab1;
create temporary table tab1(ID int auto_increment primary key,a int,b int,c int,d int);
insert into tab1(a,b,c,d) values(8,-2,4,2);
select *,(select min(col) from (select a as col union select b union select c union select d)as t where col>=0) as ord from tab1 order by ord;
/*
# ID, a, b, c, d, ord
'1', '8', '-2', '4', '2', '2'
*/