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

-------练习题

create table TestA 
(
   A int,
   B int,
   C int
)
go
insert into TestA values(10,20,30)
insert into TestA values(20,30,10)
insert into TestA values(30,10,20)
insert into TestA values(10,20,30)
go
select * from TestA

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

select * ,
		选择的列=case
		   when [A]>[B] and [A]>[C]then [A] 
		   when [B]>[A] and [B]>[C] then[B]
		   else [C]
		end
from TestA
发布了55 篇原创文章 · 获赞 4 · 访问量 1431

猜你喜欢

转载自blog.csdn.net/BowenXu11/article/details/104698559