復制代碼 代碼如下:
//創(chuàng)建成績表
create table result(
stu_id varchar2(20) not null,
china number(9,2) null,
math number(9,2) null,
english number(9,2) null
);
//插入數(shù)據(jù)
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 '優(yōu)秀'
when china>=60 then '及格'
when china60 then '不及格'
end) as 語文 ,
(case
when math>80 then '優(yōu)秀'
when math>=60 then '及格'
when math60 then '不及格'
end )as 數(shù)學 ,
(case
when english>80 then '優(yōu)秀'
when english>=60 then '及格'
when english60 then '不及格'
end) as 英語
from result