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


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

 

  

drop table table1
create table table1(
a int,
b int,
c int
)
insert into table1 values(22,24,23)

select * from table1

select (case when a>b then a else b end),(case when b>c then b else c end)
from table1

select (case when a>b then a
when a>c then a
when b>c then b else c
end)
from table1

 

 

记录下答案  昨天面试没写出来的面试题

 

posted @ 2021-09-01 14:55  蒋华  阅读(195)  评论(0编辑  收藏  举报