这篇文章呢,主要是对数据库中教学管理数据库进行简单查询的一些小练习!!!
首先呢,我们需要在数据库教学管理中建立几个表
接下来呢,就是简单的练习啦......
实验内容
实验内容
select * from student
select sname, birthday from student
select tname ,sex from teacher
select cno,cname,credit from course
select distinct cno from sc
select cno,credit from course where credit = (4)
select sname, dept, year(getdate())-year(birthday) as age from Student where SNO='s3'
select distinct sno score from SC where SCORE < 60
select sno,cno from sc where score is NULL
select sno,score from sc where score between 75 and 85
select SNAME,year(getdate())-year(birthday) as 年龄,dept
from student
where year(getdate())-year(birthday) between 20 and 22
select sname,sno,sex from student where sname like'[李王]%'
select sname,dept from student where sname like '_[晓]%'
select tname from teacher
where sal+comm > 3000 and dept = '计算机'
select tname,age from teacher
where dept = '计算机'and dept = '通信'
select * from student order by birthday desc
select sname,dept from student
where (dept = '计算机' or dept = '通信')
order by dept asc, sname desc
select sno,cno,score from sc where cno = 'c2'
order by score desc
select sno ,score from sc where sno = 's2'
order by score desc
select count(*) from student where dept = '计算机'
select max(score) 最高分,min(score) 最低分
from sc where cno = 'c3'
select avg(score) from sc where sno = 's1'
select count(cno) from sc where cno = 'c1'
select count(dept) from teacher
where tname like'王%'and dept = '计算机'
select sex,count(*)
from student
group by sex
select sex,count(*)
from teacher
group by sex
查询每个学生的学号及所有考试的平均成绩。
select sno, AVG(score)
from sc
group by sno
select cno as 课程号,count(sno) as 选课人数
from sc group by cno
select sno 学号,avg(score) 平均成绩
from sc group by sno
having count(*)>2
select sno from sc
group by sno
having min(score) >= 60
思考
select cno from sc
group by cno
having count(*)>=4
select sno 学号
from sc group by sno
having count(*)>2
order by 后根据(sno,sex)进行升序(在排序里边默认是升序)
将查询结果按照年龄,职位降序排列。
将查询结果按SEX的值分组,值相等的分为一组,每组保留一条记录。
这个查首先是按照“性别”进行分组,然后在每个性别组中再按照“所在职位”进行分组;
好啦,本篇文章就写到这里吧,可能有不足或错误之处,希望大家可以提出来哦!
都看到这了,还不得一键三连鼓励鼓励作者,哈哈哈哈