case when then else end
示例一
SELECT 学号, 姓名,
等级=
CASE
WHEN 总学分 IS NULL THEN ‘尚未选课’
WHEN 总学分 < 50 THEN ‘不及格’
WHEN 总学分 >=50 and 总学分<=52 THEN ‘合格’
ELSE ‘优秀’
END FROM XS WHERE 专业名=’计算机’
示例二
update employee
set e_wage =
case
when job_level = ’1’ then e_wage*1.08
when job_level = ’2’ then e_wage*1.07
when job_level = ’3’ then e_wage*1.06
else e_wage*1.05 // 或者else e_wage
end
示例三
select a, (case a when 1 then '中' else '国' end) AS B from table1 或者select a, (case a when 1 then '中' else a end) AS B from table1 但是a的类型必须与'中'的类型一致....因为同一字段不能存放两种不同类型的数据