数据库作业17~26

--17、 查询“95033”班学生的平均分。
select avg(degree) from Score where Sno in (Select Sno from Student where Class=95033)
--18、 假设使用如下命令建立了一个grade表:现查询所有同学的Sno、Cno和rank列。?
create table grade(low  int,upp  int,rank  char(1))
insert into grade values(90,100,‘A‘)
insert into grade values(80,89,‘B‘)
insert into grade values(70,79,‘C‘)
insert into grade values(60,69,‘D‘)
insert into grade values(0,59,‘E‘)
select *from grade
select*from score
select Sno,cno,RANK from Score join grade on Degree between low and upp order by rank
--第二种方法 select sno,cno,(select RANK from grade where Score.Degree between low and upp) as degreee from Score
--19、  查询选修“3-105”课程的成绩高于“109”号同学成绩的所有同学的记录。
select *from Score where Degree >(select Degree from Score where Sno=109 and Cno=‘3-105‘) and Cno=‘3-105‘
--20、查询score中选学多门课程的同学中分数为非最高分成绩的记录。
--这个是剔除选多门课的所有人的分数最高分
select *from Score where Sno in(select Sno from Score group by Sno having COUNT(*)>1) and Degree not in(select max(degree)from Score where Sno in(select Sno from Score group by Sno having COUNT(*)>1))

--剔除选多门课的每门课最高分
select *from Score a where Degree not in (select MAX(degree) from Score b where b.Cno=a.cno)and Sno in(select Sno from Score group by Sno having COUNT(*)>1)
--剔除除了每门课最高分学生之外的其他学生分数信息
select *from Score a where Degree not in (select MAX(degree) from Score b where b.Cno=a.cno)
--21、 查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。
select *from Score  where Degree >(select Degree from Score where Sno=109 and Cno=‘3-105‘)
--22、查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。
--时间日期函数:
--year(时间日期列):取年份
--month(时间日期列):取月份
--day(时间日期列):取天
select sno ,sname, sbirthday from student where year(Sbirthday)
=(select year(Sbirthday) from Student where Sno=108)

select DATEADD(DAY,5,‘1999-08-31‘)--在原来的基础上加5天
select DATEADD(week,5,‘1999-08-31‘)--在原来的基础上加5周
select DATEDIFF(WEEKDAY,‘2015-04-23‘,‘2015-05-01‘) --两天之间相差几天(weekday),相差几周(week)
print datename(weekday,‘2015-4-23‘) --返回今天星期几--
print datename(week,‘2015-4-23‘) --返回这是今年的第多少个周
print datepart(weekday,‘2015-4-23‘) --返回这是今年的第多少个周 返回int类型的 datepart
print getdate()--获取当前系统时间
print isdate(‘1999-111-213‘)--判断一个值是否为正确的日期时间 1:正确 0:错误
print sysdatetime() --获取更为详细的时间

--23、查询“张旭“教师任课的学生成绩。
select sno,degree from Score where Cno=(select Cno from Course where Tno = (Select Tno from Teacher where Tname=‘张旭‘))
--select sno,degree from Course join Score on Course.Cno=Score.Cno join teacher on Course.tno=teacher.tno where Tname=‘张旭‘
--
select *from Teacher
select *from Course
select *from Score
select *from Student

--24、查询选修某课程的同学人数多于5人的教师姓名。
select tname from teacher where tno
=(select Tno from course where cno=
(select cno from Score
 group by cno having COUNT(*)>5))

--
--select Tno from course where Cno in
--(select score.Cno from Course
--join Score on Score.Cno=Course.Cno
--group by score.cno having COUNT(*)>5)
--25、查询95033班和95031班全体学生的记录。
select *from Student where Class in(95033,95031)
--26、  查询存在有85分以上成绩的课程Cno.
select distinct Cno from Score  where Degree>85
时间: 2024-08-05 06:01:38

数据库作业17~26的相关文章

数据库作业14——综合练习(二) 反馈情况

数据库作业14--综合练习(二) 反馈情况 一.作业要求复述 1.创建数据库CPXS,保存于E盘根目录下以自己学号+姓第一个字母(阿拉伯数字+大写字母)方式创建的文件夹中,初始大小5MB,最大20MB,以10%方式增长,日志文件存于同一文件夹,初始大小2MB,最大5MB,以1MB方式增长: 2.创建表CP,CPBH为主键,8位数字,CPMC,长度12个字符,JG为精确到小数点后2位,KCL为整数,除了KCL,其他都不能为空: 3.使用INSERT输入数据,具体数据如下: '10001100',

10月20日上午SQl数据库作业解析

设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1-2的表(一)~表(四)所示.用SQL语句创建四个表并完成相关题目.                  表1-1数据库的表结构 表(一)Student (学生表)                         字段名 数据类型 可否为空 含 义 Sno varchar(20) 否 学号(主键) Sname

数据库作业[定时执行任务]的创建 (转帖)

--每月执行的作业exec p_createjob @jobname='mm',@sql='select * from syscolumns',@freqtype='month'--每周执行的作业exec p_createjob @jobname='ww',@sql='select * from syscolumns',@freqtype='week'--每日执行的作业exec p_createjob @jobname='a',@sql='select * from syscolumns'--每

数据库作业[定时执行任务]的创建

--每月执行的作业 exec p_createjob @jobname='mm',@sql='select * from syscolumns',@freqtype='month' --每周执行的作业 exec p_createjob @jobname='ww',@sql='select * from syscolumns',@freqtype='week' --每日执行的作业 exec p_createjob @jobname='a',@sql='select * from syscolumn

第二次数据库作业--gui

1 package gui; 2 3 import action.C2SAction; 4 import action.CourseAction; 5 import action.StudentAction; 6 import javafx.application.Application; 7 import javafx.geometry.Insets; 8 import javafx.scene.Scene; 9 import javafx.scene.control.*; 10 import

SQL 数据库作业。

1 create table Student---------学生表 2 3 (Sno char(50) primary key not null,---------------学号 4 Sname char(50) not null,----------------------学生姓名 5 Ssex char(8) not null,----------------------学生性别 6 Sbirthday datetime null,----------------学生生日 7 Class

数据库作业

第四章作业 1. 什么是数据库安全性? 答:数据库的安全性是指保护数据库以防止不合法的使用所造成的数据泄露.更改或破坏. 2. 试述实现数据库安全性控制的常用方法和技术. 答:实现数据库安全性控制的常用方法和技术有:  (1)用户标识和鉴别:该方法由系统提供一定的方式让用户标识自己的名字或身份.每次用户要求进入系统时,由系统进行核对,通过鉴定后才提供系统的使用权.  (2)存取控制:通过用户权限定义和合法权检查确保只有合法权限的用户访问数据库,所有未被授权的人员无法存取数据.例如 C2 级中的自

Oracle数据库作业-5 查询

14.查询所有学生的Sname.Cno和Degree列. select t.sname,c.cno,c.degree from student t inner join score c on t.sno=c.sno 15.查询所有学生的Sno.Cname和Degree列. select t.sno,s.degree,c.cname from student t ,score s,course c where t.sno=s.sno and s.cno=c.cno 16.查询所有学生的Sname.

SQLSEVER数据库作业2

1.使用企业管理器新建一个数据库,名称为"图书数据库",其主要数据文件大小为2M,次要数据文件大小为1M,日志文件大小为1M,存放位置为"D:\SQLServer",其他选项都采用默认值 .(如操作不成功,分析原因,并按相关要求建立"图书数据库") 新建查询 CREATE DATABASE 图书馆数据库 ON ( NAME="图书数据库DB", FILENAME="D:\SQLSever\图书馆数据库db.mdf&q