復制代碼 代碼如下:
//創建成績表
create table result(
stu_id varchar2(20) not null,
china number(9,2) null,
math number(9,2) null,
english number(9,2) null
);
//插入數據
insert into result values('0001',60,20,80);
insert into result values('0002',80,60,80);
insert into result values('0003',20,85,80);
select *from result;
//條件查詢
select stu_id,(case
when china>80 then '優秀'
when china>=60 then '及格'
when china<60 then '不及格'
end) as 語文 ,
(case
when math>80 then '優秀'
when math>=60 then '及格'
when math<60 then '不及格'
end )as 數學 ,
(case
when english>80 then '優秀'
when english>=60 then '及格'
when english<60 then '不及格'
end) as 英語
from result