博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
百度 实验三
阅读量:7173 次
发布时间:2019-06-29

本文共 1719 字,大约阅读时间需要 5 分钟。

1、将数据分别插入表S、C、SC;(各插入两条记录) insert into s  values('0257','张一','男',25,'CS'), ('0258','张二','男',23,'IS') insert into c  values('7','web编程基础','3',5), ('8','计算机导论','4',3)      insert into sc  values('0257','7',56), ('0258','8',96) 2、将表S、C、SC中的数据分别以.SQL文件或.txt文件的形式保存在磁盘上。 3、在表S、C、SC上练习数据的插入、修改、删除操作。(比较在表上定义/未定义主码(Primary Key)或外码(Foreign Key)时的情况) 4、将表S、C、SC中的数据全部删除,再利用磁盘上备份的数据来恢复数据。 5、如果要在表SC中插入某个学生的选课信息(如:学号为“200215121”,课程号为“5”,成绩待定),应如何进行? insert into sc(sno,cno,grade) values('200215121','5',null) 6、求各系学生的平均成绩,并把结果存入数据库Dept_grade 表,Dept_grade创建如下;create  table  Dept_grade ( Sdept char(15), Avg_grade  smallint )

insert into Dept_grade

select sdept,AVG(grade)

from sc,s

where sc.sno=s.sno

group by sdept

 

 

7、将“CS”系全体学生的成绩置零;

 

update sc

set grade='0'

where sno  in

(

select sno

from s

where sdept='cs'

)

 

 

8、删除“CS”系全体学生的选课记录;

 

delete from sc

where sno 

in(

select  sno from s

where sdept='cs'

)

9、删除学号为“0251”的相关信息;

 

delete from s

where sno='0251'

10、将学号为“0251”的学生的学号修改为“S0251”;

 

update s

set sno='s0251'

where sno='0251'

11、把平均成绩大于分的男同学的学号和平均成绩存入另一个表S_GRADE(SNO,AVG_GRADE);

 

create table S_GRADE

(

SNO char(10),

AVG_GRADE float

)

 

insert into S_GRADE

select sno,AVG(grade)

from sc where sno

in(

select  sno from s

where ssex='男')

group by sno

having AVG(grade)>80

 

12、把选修了课程名为“数据结构”的学生的各门课成绩提高%;

 

update sc

set grade=grade*1.1

where sno in

(

select sno from sc,c

where sc.cno=c.cno and cname='数据结构')

 

13、把选修了“2”号课程,且成绩低于该门课程的平均成绩的学生的成绩提高%;

 

update sc

set grade=grade*1.05

where grade<

(

select  AVG(grade)

from sc

where cno='2'

group by cno

)

 

14、把选修了“2”号课程,且成绩低于该门课程的平均成绩的学生成绩删除掉;

delete from sc

where cno='2'and grade<

(

select AVG(grade)

from  sc

where cno='2'

group by cno

)

 

  

  

转载于:https://www.cnblogs.com/wc1903036673/p/3409069.html

你可能感兴趣的文章
AIDL基本使用
查看>>
MySQL中间件之ProxySQL(6):管理后端节点
查看>>
Mathematica 取整函数
查看>>
(转)Awsome Domain-Adaptation
查看>>
利用cwRsync客户端将Windows下文件同步到Linux
查看>>
npm常用命令
查看>>
String,StringBuffer和StringBuilder三者的讲解
查看>>
Understanding Digital Raw Capture
查看>>
(原創) unnamed object的多型只能使用reference (C/C++)
查看>>
10种有用的CSS技巧
查看>>
linux命令tree用法详解
查看>>
matlab练习程序(TV模型图像修复)
查看>>
用户接口(UI)设计的 20 条原则
查看>>
Windows Azure HandBook (3) 浅谈Azure安全性
查看>>
div+css布局入门
查看>>
Linux 下Apache和Resin的安装
查看>>
HDU 2710 Max Factorv (素数模板 & 多种解法)
查看>>
Linux 启动流程
查看>>
获得汉字字符串的首个拼音字母的缩写
查看>>
RegularExpressionValidator控件与常用验证正则表达式大全小结
查看>>