表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列

if object_Id('testTb')is not null drop table testTb
go
create table testTb (A int , B int ,C int)
insert into testTb
select 1,2,3 union all
select 1,3,2 union all
select 2,1,3 union all
select 3,1,4

select
     (case when A > B then A else B end) as E,
     (case when B > C then B else C end) as F
from testTb
drop table testTb

原文地址:https://www.cnblogs.com/aisini/p/1688445.html