日期:2014-05-18 浏览次数:20478 次
select a , b , newcol = b+c from tabletemp where flag = '是' union all select a , b , newcol = b+f from tabletemp where flag = '否' order by id
------解决方案--------------------
select a,b,b+c from tabletemp where flag='是'
union
select a,b,b+c from tabletemp flag='否'
order by id
------解决方案--------------------
--一共三个,你看哪个合适? select a , b , newcol from ( select id , a , b , newcol = b+c from tabletemp where flag = '是' union all select id , a , b , newcol = b+f from tabletemp where flag = '否' ) t order by id
------解决方案--------------------
select a , b , newcol = b+ case when flag = '是' then c else f end
from tabletemp
------解决方案--------------------
select a , b , newcol = b+ case when flag = '是' then c else f end
from tabletemp
order by id