新建视图,修改视图,删除视图(用到的表和上一个博文的表一样)
create view vw_StudentScore
as
select
sName,
sAge,
case
when english IS null then '缺考'
else CONVERT(varchar(50),math)
end as english,
是否报考=
case
when scoreId IS null then '未报考'
else '已报考'
end,
是否合格=
case
when english>=60 and math>=60 then '合格'
else '不合格'
end
from Student
left join Score
on Score.studentId=Student.sId
select * from vw_StudentScore
select * from Student
update Student set sName='山西关羽' where sName='关羽'
drop view vw_StudentScore
------------------------------------
create view vw2
as
select sName,
case
when sAge>13 and sAge<16 then'豆蔻年华'
when sAge>50 then 'oldman'
else '青少年'
end as '状态'
from Student
select * from vw2
drop view vw2