if exists(select * from sys.databases where name ='stuDB1')
drop database stuDB1
go
create database stuDB1
go
use stuDB1
go
create table stuInfo11
(
stuNo int identity,
stuName nvarchar(16),
sttuAge int,
grade float,
statuss int
)
insert into stuInfo11 values('夏冬',55,20,1)
insert into stuInfo11 values('马超',464,40,1)
insert into stuInfo11 values('张辽',554,60,1)
insert into stuInfo11 values('马岱',54,80,1)
insert into stuInfo11 values('徐晃',88,100,0)
insert into stuInfo11 values('曹仁',88,100,null)
--case 简单格式是一组比较表达式,以确定结果
select stuName,case statuss
when 0 then '请假中'
when 1 then '正常上课'
else '不知去向' end as '在校否'
from stuInfo11
--比较格式
select stuName ,case
when grade>99 then '你是最棒的!'
when grade >=80 then '优秀'
when grade >=60 then '及格'
else '不及格或为参考'
end '考试等级'
from stuInfo11
所有执行后结果如下