表中有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

posted @ 2010-03-17 19:28  北纬28.33  阅读(1049)  评论(0编辑  收藏  举报