首页 > 数据库技术 > 详细

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

时间:2017-07-21 16:38:57      阅读:259      评论:0      收藏:0      [点我收藏+]

.请教一个面试中遇到的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

    1. drop table table1  
    2. create table table1(  
    3.     a int,  
    4.     b int,  
    5.     c int  
    6. )  
    7. insert into table1 values(22,24,23)  
    8.   
    9. select * from table1  
    10.   
    11. select (case when a>b then a else b end),(case when b>c then b else c end)  
    12. from table1  
    13.   
    14. select (case when a>b then a  
    15.              when a>c then a  
    16.              when b>c then b else c  
    17.              end)  
    18. from table1 

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

原文:http://www.cnblogs.com/ghjbk/p/7218139.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!