怎么用一条sql语句查出学生表成绩小于60为不及格60-80为良好80-90为优秀?

2025-03-10 01:34:52
推荐回答(3个)
回答1:

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

回答2:

select sName,sNO,sScore,状态=case when sScore <60 then '不及格' when sScore >=60 and sScore <80 then '良好 when sScore>=80 and sScore <90 then '优秀' when sScore >=90 then '优异' end
from 学生表

可以试一下.

回答3:

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