SQL基本操作——case end

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

结果:

posted @ 2017-10-16 23:48  var_obj  阅读(832)  评论(0编辑  收藏  举报