【MySQL】查询学生成绩,并作详细分级:

【MySQL】查询学生成绩,并作详细分级:

case ... end 语句做嵌套

 

#创建学生成绩

#创建学生成绩
create database test;
use test;
create table course
(
	Student_id char(12) not null comment "学号",
	Course_id char(4) not null comment "课程号",
	score int default 0 comment "成绩"
);

insert into course values
	("201810101101","1001",65),
	("201810101102","1001",76),
	("201810101103","1001",87),
	("201810101104","1001",69),
	("201810101105","1001",96),
	("201810101106","1001",82),
	("201810101107","1001",72),
	("201810101108","1001",64);

 

select
	Student_id as 学号,
	Course_id as 课程编号,
	(case when score >= 90  then "优秀" 
	else
			(case when score >= 80 then "良好"
			else
					(case when score >=70 then "中等" 
					else
							(case when score>=60 then "及格" else "不及格" end)
					end)
			end)
	end) as 成绩情况
from course;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yangbocsu

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值