在数据库中将一个表中成绩划分5个等级

在数据库中将一个表中成绩划分5个等级,第1张

select case

when 成绩 >= 90 then

'优'

when 成绩 >= 80 then

'良'

when 成绩 >= 70 then

'中'

when 成绩 >= 60 then

'差'

else

'不及格'

end as 等级

from 表

with etc as

(

SELECT A.S# as s#,B.CNAME as cname,A.GRADE as grade FROM SC AS A JOIN C AS B

ON A.C#=B.C#)

select a.sname as 姓名,b.cname as 课程名,

(case when grade >=90 and grade <=100 then 'A'

when grade >=80 and grade <=89 then 'B'

when grade>=70 and grade<=79 then 'C'

else 'D' end) as 成绩

from s as a join etc as b

on a.s#=b.s#

order by b.grade desc

select name,case when 成绩<60 then 不及格 when 成绩>=60 and 成绩<80 then 良好 when 成绩>=0 and 成绩<90 then 优秀 end as 成绩情况 ,from 表名。

注意,在输入sql语句的时候,要在英文环境下输入。否则可能会出现代码不识别。

拓展内容:

结构化查询语言(Structured Query Language)简称SQL,结构化查询语言是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统。sql 语句就是对数据库进行 *** 作的一种语言。

一些sql 语句示例如下:

数据库:CREATE DATABASE database-name

删除数据:drop database dbname

创建表:create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)

删除新表:drop table tabname

增加:Alter table tabname add column col type

设主键:Alter table tabname add primary key(col)

删除主键:Alter table tabname drop primary key(col)

创建索引:create [unique] index idxname on tabname(col….)

删除索引:drop index idxname

创建视图:create view viewname as select statement

删除视图:drop view viewname


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9260343.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-26
下一篇 2023-04-26

发表评论

登录后才能评论

评论列表(0条)

保存