莫愁前路无知己,天下谁人不识君。。。。

SQL面试题003

上一篇 / 下一篇  2018-03-22 11:14:01 / 个人分类:软件面试问题

SQL面试题:
表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列。
------------------------------------------
select (case when a>b then a else b end ),
(case when b>c then b esle c end)
from table_name
-----------------------------------------
select if(a>b,a,b),if(b>c,b,c) from 表名
-------------------------------------------------
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  

TAG: 选择SQL

 

评分:0

我来说两句

Open Toolbar