日期:2014-05-17 浏览次数:20644 次
if object_id('a6') is not null
drop table a6
go
create table a6
(
NAME NVARCHAR(20),
grade int
)
go
insert into a6
select '小同1',70 union all
select '小同2',65 union all
select '小同3',20 union all
select '小同4',12 union all
select '小同5',80
go
select *,
(case when grade >=60 then '及格' else '不及格' end)[分类] from a6
--引用 ZaoLianBuXiQi
if object_id('a6') is not null
drop table a6
go
create table a6
(
NAME NVARCHAR(20),
grade int
)
go
insert into a6
select '小同1',70 union all
select '小同2',65 union all
select '小同3',20 union all
select '小同4',12 union all
select '小同5',80
----------------------------------
Select *,Case
When grade < 60 then '不及格'
When grade >60 And grade <80 then '及格'
else '优秀' end as fg
From a6
------------用计算列
Alter table a6
add fg as (Case When grade< 60 then '不及格'
else Case when grade < 80 then '及格'
else '优秀' end
end )
Select *
From a6
----------------
小同1 70 及格
小同2 65 及格
小同3 20 不及格
小同4 12 不及格
小同5 80 优秀
select 姓名,
成绩,
case when 成绩>=80 then '优秀'
when 成绩<80 and 成绩>=60 then '及格'
when 成绩<60 then '不及格' end '分类'
from [表名]