数据查询(提高篇)-------实验五_数据库查询1999年出生的学生(1)

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

6.查询不是CS学院的学生姓名、年龄、系别 (三种方法实现)
select sname,sage,sdept from student where sdept not in(‘CS’)

select sname,sage,sdept from student where sdept!=‘CS’

select sname,sage,sdept from student where sdept not like ‘CS’


select sname,sage,sdept from student where sno not in(
select sno from student where sdept like ‘CS’ )

select sname,sage,sdept from student where sno in(select sno from student where sdept not like ‘CS’ )

select sname,sage,sdept from student s1 where not exists(select * from student s2 where sdept='cs’and s1.sno=sno)

7.查询年龄在19-20岁的学生学号、姓名、系别、年龄
select sno,sname,sage,sdept from student where sage between 19 and 20
select sno,sname,sage,sdept from student where sage>=19 and sage<=20

8.查询姓刘的学生情况
select * from student where sname like ‘刘%’

9.查询姓刘或姓李的学生情况 (注意不同的写法)
select * from student where sname like ‘刘%’ or sname like ‘李%’
select * from student where sname like ‘[刘李]%’

10.查询姓刘且名字为两个字的学生情况
select * from student where sname like ‘刘_’

11.查询1999年以后出生的学生姓名
select sname,year(getdate())-sage birth from student where year(getdate())-sage>1999

12.利用内部函数year()查询CS学院学生的出生年份
select sname,year(getdate())-sage birth from student where sdept=‘cs’
13.查询全体学生情况,查询结果按所在系升序排列,对同一系中的学生按年龄降序排列。
select * from student order by sdept,sage desc
14.查询学生总人数
select count() renshu from student
15.查询选修了课程的学生人数(两种方法实现)
select count(
)renshu from student where exists (select * from sc where student.sno=sc.sno)
select count(distinct sno) xuanxiurenhsu from sc
16.查询选修了2号课程的学生总人数和平均成绩
select count(*) renshu,avg(grade) average from sc where cno=‘2’

17.查询选修2号课程学生的最好成绩
select max(grade) from sc where cno=‘2’
18.查询每个系的系名及学生人数
select sdept,count(*) renshu from student group by sdept

19.查询每门课的选修人数及平均成绩
select cno,count(*)renshu,avg(grade) average from sc group by cno

20.查询没有被选修的课程信息(两种方法实现)
select * from course where cno not in(select distinct cno from sc)
select * from course where not EXISTS (select * from sc where cno=course.cno)

create database EDUC
create table student(sno char(8) primary key,sname char(8),ssex char(2) constraint ck_student_ssex check(ssex=‘男’ or ssex=‘女’),sage int,sdept char(10))
create table course(cno char(2) primary key,cname char(30),criedit int,cpno char(3))
create table sc(sno char(8),cno char(2),grade int constraint ck_sc_grade check(grade<=100 and grade>=1),primary key(sno,cno),
foreign key(sno) references student(sno),foreign key(cno) references course(cno))
insert into student(sno,sname,ssex,sage,sdept)
values(‘95001’,‘李勇’,‘男’,‘20’,‘CS’)
insert into student(sno,sname,ssex,sage,sdept)
values(‘95002’,‘刘晨’,‘女’,‘19’,‘IS’)
insert into student(sno,sname,ssex,sage,sdept)
values(‘95003’,‘王敏’,‘女’,‘18’,‘MA’)
insert into student(sno,sname,ssex,sage,sdept)
values(‘95004’,‘张立’,‘男’,‘19’,‘IS’)
insert into student(sno,sname,ssex,sage,sdept)
values(‘95005’,‘刘云云’,‘女’,‘18’,‘CS’)
insert into course(cno,cname,criedit,cpno)
values(‘1’,‘数据库’,‘4’,‘5’)
insert into course(cno,cname,criedit,cpno)
values(‘2’,‘数学’,‘6’,‘’)
insert into course(cno,cname,criedit,cpno)
values(‘3’,‘信息系统’,‘3’,‘1’)
insert into course(cno,cname,criedit,cpno)
values(‘4’,‘操作系统’,‘4’,‘6’)
insert into course(cno,cname,criedit,cpno)
values(‘5’,‘数据结构’,‘4’,‘7’)
insert into course(cno,cname,criedit,cpno)
values(‘6’,‘数据处理’,‘3’,‘’)
insert into course(cno,cname,criedit,cpno)
values(‘7’,‘PASCAL语言’,‘4’,‘6’)
insert into sc(sno,cno,grade)
values(‘95001’,‘1’,‘92’)
insert into sc(sno,cno,grade)
values(‘95001’,‘2’,‘85’)
insert into sc(sno,cno,grade)
values(‘95001’,‘3’,‘88’)
insert into sc(sno,cno,grade)
values(‘95002’,‘2’,‘90’)
insert into sc(sno,cno,grade)
values(‘95002’,‘3’,‘80’)
insert into sc(sno,cno,grade)
values(‘95003’,‘2’,‘85’)
insert into sc(sno,cno,grade)
values(‘95004’,‘1’,‘58’)
insert into sc(sno,cno,grade)
values(‘95004’,‘2’,‘85’)

–1.查询全体学生的学号和姓名
select sno,sname from student

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

4f45ff00ff254613a03fab5e56a57acb)**

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 26
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值