课堂练习

2018.12.26课堂练习

1.使用如下语句,创建学生表student和班级表class
create table student ( – 学生表
xh char(4),-- 学号
xm varchar(10),-- 姓名
sex char(2),-- 性别
birthday date,-- 出生日期
sal double(7,2), – 奖学金
studentcid int(2) – 学生班级号
)
Create table class ( – 班级表
classid int(2), – 班级编号
cname varchar(20),-- 班级名称
ccount int(3) – 班级人数
)
2.基于上述学生表和班级表,完成如下问题
(1)添加三个班级信息为:1,JAVA1班,null
2,JAVA2班,null
3,JAVA3班,null
(2)添加学生信息如下:‘A001’,‘张三’,‘男’,‘01-5月-05’,100,1
(3)添加学生信息如下:‘A002’,‘MIKE’,‘男’,‘1905-05-06’,10
(4)插入部分学生信息: ‘A003’,‘JOHN’,'女’
(5)将A001学生性别修改为’女‘
(6)将A001学生信息修改如下:性别为男,生日设置为1980-04-01
(7)将生日为空的学生班级修改为Java3班
(8)请使用一条SQL语句,使用子查询,更新班级表中每个班级的人数字段

insert into class values(1,'JAVA1班',null),(2,'JAVA2班',null),(3,'JAVA3班',null)
insert into student values('A001','张三','男','2005-05-01',100,1)
insert into student values('A002','MIKE','男','1905-05-06',10,null)
insert into student values('A003','JOHN','女',null,null,null)
update student set sex = '女' where xh = 'A001'
update student set sex = '男',birthday = '1980-04-01' where xh = 'A001'
update student set studentcid = (select classid from class where cname = 'JAVA3班') where birthday is null
update class c set ccount = (select count(*) from student where studentcid = c.classid)

3.使用如下语句,建立以下表
CREATE TABLE copy_emp (
empno int(4),
ename varchar(20),
hiredate date,
deptno int(2),
sal double(8,2))
4.在第三题表的基础上,完成下列问题
(1)在表copy_emp中插入数据,要求sal字段插入空值,部门号50,参加工作时间为2000年1月1日,其他字段随意
(2)在表copy_emp中插入数据,要求把emp表中部门号为10号部门的员工信息插入
(3)修改copy_emp表中数据,要求10号部门所有员工涨20%的工资
(4)修改copy_emp表中sal为空的记录,工资修改为平均工资
(5)把工资为平均工资的员工,工资修改为空
(6)另外打开窗口2查看以上修改
(7)执行commit,窗口2中再次查看以上信息
(8)删除工资为空的员工信息
(9)执行rollback

insert into copy_emp values (1000,'tom','2000-1-1',50,null)
insert into copy_emp (empno,ename,hiredate,deptno,sal)
select empno,ename,hiredate,deptno,sal from emp where deptno = 10
update copy_emp set sal = sal * 1.2 where deptno = 10
update copy_emp set sal = (select avgsal from (select avg(sal) avgsal from copy_emp) a) where sal is null
update copy_emp set sal = null where sal = (select avgsal from (select avg(sal) avgsal from copy_emp) a)
delete from copy_emp where sal is null 

6.7.9略

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值