码迷,mamicode.com
首页 > 数据库 > 详细

SQL基本操作——case end

时间:2017-10-17 00:20:42      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:分享   .com   成绩   div   image   查询   code   class   strong   

case end进行多条件的判断

--查看Person表
select * from Person

技术分享

--对math字段进行条件判断
select name,数学成绩=
case
    when math>100 then 
    when math>90 then 
    when math>80 then 
    when math>70 then 及格
    when math is NULL then 缺考
    else 不及格
end
from Person

结果:

技术分享

--查询t8表
select * from t8

技术分享

--对相邻两个表的值进行大小判断
select
A与B列中的最大值=
case
    when A>B then A else B
end,
B与C列中的最大值=
case
    when B>C then B else C
end
from t8

结果:

技术分享

SQL基本操作——case end

标签:分享   .com   成绩   div   image   查询   code   class   strong   

原文地址:http://www.cnblogs.com/wuqiuxue/p/7679568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!