数据库练习题(大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及格)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_16845639/article/details/78088499

4.有一张表,里面有3个字段:语文,数学,英语。其中有3条记录分别表示语文70分,数学80分,英语58分,请用一条sql语句查询出这三条记录并按以下条件显示出来(并写出您的思路):
大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及格。
显示格式:
语文 数学 英语
及格 优秀 不及格

drop table if exists classestest;
create table classestest (eid bigint(10) not null auto_increment,yuwen int(3) default null,shuxue int(3) default null,yingyu int(3) default null,primary key (eid)) engine=InnoDB auto_increment=1 default charset=utf8 comment='学科测试表';

这里写图片描述

insert into classestest (yuwen,shuxue,yingyu) values (70,80,58);
select (case when yuwen>=80 then '优秀' when yuwen>=60 then '及格' else '不及格' end) as 语文,(case when shuxue>=80 then '优秀' when shuxue>=60 then '及格' else '不及格' end) as 数学,(case when yingyu>=80 then '优秀' when yingyu>=60 then '及格' else '不及格' end) as 英语 from classestest;

这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_16845639/article/details/78088499