根据表中列值比较大小显示不同结果
我有一个表
select a,b,c from biaotable
我想想要的结果是:
如果 a >c 则显示select a,b,c,(a - c) as d from biaotable
如果 c > b 则显示 select a,b,c,(c - b ) as d from biaotable
请高手帮忙写到一条SQL语句中,谢谢!
------解决方案--------------------你逻辑混乱了.
a>c和c>b是可共存的条件. 那么这里怎么取?
------解决方案--------------------如果 a > c 则显示select a,b,c,(a - c) as d from biaotable
如果 c > b 则显示 select a,b,c,(c - b ) as d from biaotable
SQL code
select
*,d=case when a>c then a-c
when c>b then c-b
end
from biaotable