Skip to content

常用查询语句

作者:Lee 等
最后更新:

基本语句

sql
select *
from student

Where 查询

sql
select *
from student
where Address = '鞍山'

例:在 SC 表中成绩高于 80 分的人

sql
select *
from SC
where chengji > 80

例:查询 ST 表中所有女生的学号和姓名

sql
select STid,STname
from ST
where sex = '女'

例:在 SC 表中成绩在 70-79 分的人

sql
select *
from SC
where chengji >=70 and chengji <= 79

Where not

sql
select *
from SC
where ID not in('001','002')

查询 SC 表中成绩非空且>90

sql
select *
from SC
where chengji is not null and chengji >= 90

Where like

例:查询所有姓张的学生

sql
select *
from ST
where STname like '张%'

例:查询所有不姓张的学生

sql
select *
from ST
where STname not like '张%'

例:查询所有不姓张且名字是三个汉字的学生

sql
select *
from ST
where STname not like '张__'

between and

例:在 SC 表中成绩在 70-79 分的人

sql
select *
from SC
where between 70 and 79

distinct

distinct 去除重复值

例:查询学生来自哪些城市

sql
select distinct address
from ST

查询有人选修的课程的课程数

sql
select count(distinct SCid)
from SC

count

例:查询城市数量

sql
select count(distinct address)
from ST

AVG(平均值)

例:查询特定课程 id 下的平均值

sql
select AVG(chengji)
from SC
where SCid = '111100'

页面历史