select 学生姓名,(case when 语文>=80 then '优秀' when 语文>=60 then '及格' else '不及格') as 语文, (case when 数学>=80 then '优秀' when 数学>=60 then '及格' else '不及格') as 数学, (case when 英语>=80 then '优秀' when 英语>=60 then '及格' else '不及格') as 英语, from table
select 学生姓名,科目名, case when score>=80 then '优秀' when score>=60 and score<80 then '及格' else '不及格' end as 学科状态 from 学生成绩表
select 学生姓名,科目名, (case when score>80 then '优秀' when score>=60 and score<80 then '及格' else '不及格' end) as 学科状态 from 学生成绩表
select 学生姓名,科目名, decode(trunc((score-40)/20),0,'不及格',1,'及格','优秀') as 学科状态 from 学生成绩表
用 case when 也是一样的、
目前认为表结构为(学生姓名,课程名,成绩) 参考代码如下:SELECT 学生姓名,科目名, (CASE WHEN 成绩>80 THEN '优秀' WHEN 成绩>=60 AND 成绩<80 THEN '及格' ELSE '不及格' END) as 学科状态 FROM 表名; 注意:不能使decode,因为decode无法判断范围,它只能与离散的具体值做比较。
可以的 不过有点麻烦 不如用case when select 学生姓名,科目名, decode(sign(score-20),-1,'不及格',decode(trunc((score-40)/20),0,'不及格',1,'及格','优秀')) as 学科状态 from 学生成绩表
when 语文>=60 then '及格'
else '不及格') as 语文,
(case when 数学>=80 then '优秀'
when 数学>=60 then '及格'
else '不及格') as 数学,
(case when 英语>=80 then '优秀'
when 英语>=60 then '及格'
else '不及格') as 英语,
from table
select 学生姓名,科目名,
case when score>=80 then '优秀'
when score>=60 and score<80 then '及格'
else '不及格' end as 学科状态
from 学生成绩表
(case when score>80 then '优秀' when score>=60 and score<80 then '及格'
else '不及格' end) as 学科状态 from 学生成绩表
或者case when
能不能用decode写具体点,我之前从来没有用过decode啊?
select 学生姓名,科目名, decode(trunc((score-40)/20),0,'不及格',1,'及格','优秀') as 学科状态 from 学生成绩表
参考代码如下:SELECT 学生姓名,科目名,
(CASE WHEN 成绩>80 THEN '优秀'
WHEN 成绩>=60 AND 成绩<80 THEN '及格'
ELSE '不及格' END) as 学科状态
FROM 表名;
注意:不能使decode,因为decode无法判断范围,它只能与离散的具体值做比较。
可以的 不过有点麻烦 不如用case when select 学生姓名,科目名, decode(sign(score-20),-1,'不及格',decode(trunc((score-40)/20),0,'不及格',1,'及格','优秀')) as 学科状态 from 学生成绩表