山东大学数据库实验3(2021年最新版)

山东大学数据库实验3(2021年最新版)

本人分步写的,中间有空行的话,代表上一步结束,转向下一步,一个题 由多步完成

3-1
create table test3_01 as
select * from pub.student_31
where (
substr(sid,0,1) in('0','1','2','3','4','5','6','7','8','9')and 
substr(sid,1,1) in('0','1','2','3','4','5','6','7','8','9')and 
substr(sid,2,1) in('0','1','2','3','4','5','6','7','8','9') and 
substr(sid,3,1) in('0','1','2','3','4','5','6','7','8','9') and
substr(sid,4,1) in('0','1','2','3','4','5','6','7','8','9') and
substr(sid,5,1) in('0','1','2','3','4','5','6','7','8','9') and
substr(sid,6,1) in('0','1','2','3','4','5','6','7','8','9') and
substr(sid,7,1) in('0','1','2','3','4','5','6','7','8','9') and
substr(sid,8,1) in('0','1','2','3','4','5','6','7','8','9') and
substr(sid,9,1) in('0','1','2','3','4','5','6','7','8','9') and
substr(sid,10,1) in('0','1','2','3','4','5','6','7','8','9') and
substr(sid,11,1) in('0','1','2','3','4','5','6','7','8','9') and
substr(sid,12,1) in('0','1','2','3','4','5','6','7','8','9'));
3-2
create table test3_02 as
select * from pub.student_31
where ( extract(year from birthday)=2012-age);
3-3
create table test3_03 as
select * from pub.student_31
where (sex in ('女','男') or (sex is null));


3-4
create table test3_04 as
select * from pub.student_31                     
where (dname is not null and  dname like'___%'and length(dname)=length(trim(dname));

delete from test3_04
where instr(dname,' ')>0;//删除名字内部有空格的数据
instr()函数的格式  (俗称:字符查找函数)
格式一:instr( string1, string2 )    // instr(源字符串, 目标字符串)
格式二:instr( string1, string2 [, start_position [, nth_appearance ] ] )   // instr(源字符串, 目标字符串, 起始位置, 匹配序号)
解析:string2 的值要在string1中查找,是从start_position给出的数值(即:位置)开始在string1检索,检索第nth_appearance(几)次出现string2

length(dname)=length(trim(dname)//确保院名尾部没有空格,因为trim(字段)是去掉字符串后面的空格
3-5
create table test3_05 as
select * 
from pub.student_31

delete from test3_05
where class in(
select class
from pub.student_31
group by class
having count(*)<50 );//按照class分组计数的话,不规范的数据的count会是个位数,用这个方法去除数据库中不规范的数,而不要人工去看数据格式从而去除不规范数据

3-6
1
delete from test3_06
where(
substr(sid,0,1) not in('0','1','2','3','4','5','6','7','8','9') or 
substr(sid,1,1) not in('0','1','2','3','4','5','6','7','8','9') or 
substr(sid,2,1) not in('0','1','2','3','4','5','6','7','8','9') or 
substr(sid,3,1) not in('0','1','2','3','4','5','6','7','8','9') or
substr(sid,4,1) not in('0','1','2','3','4','5','6','7','8','9') or
substr(sid,5,1) not in('0','1','2','3','4','5','6','7','8','9') or
substr(sid,6,1) not in('0','1','2','3','4','5','6','7','8','9') or
substr(sid,7,1) not in('0','1','2','3','4','5','6','7','8','9') or
substr(sid,8,1) not in('0','1','2','3','4','5','6','7','8','9') or
substr(sid,9,1) not in('0','1','2','3','4','5','6','7','8','9') or
substr(sid,10,1) not in('0','1','2','3','4','5','6','7','8','9') or
substr(sid,11,1) not in('0','1','2','3','4','5','6','7','8','9') or
substr(sid,12,1) not in('0','1','2','3','4','5','6','7','8','9'))
2
delete from test3_06
where(
extract(year from birthday)!=2012-age
);
3
delete from test3_06
where(
(instr(name,' ')>0 )or (length(trim(name))<=1)
);
4
delete from test3_06
where(
sex not in ('女','男')
);
5
delete from test3_06
where(
instr(dname,' ')>0 or dname is null
);
6
delete from test3_06
where(
length(trim(dname))<3
);
7
delete from test3_06
where(
class in(
select class
from pub.student_31
group by class
having count(*)<30 )
);


3-7

create table test3_07 as
select *
from pub.Student_course_32 natural join pub.student;

3-8
create table test3_08 as
select *
from pub.Student_course_32 natural join pub.teacher_course;

3-9
create table test3_09 as
select *
from pub.Student_course_32 
where score>=0 and score<=100;
3-10
最后一个条件:
delete from test3_10
where ( cid,tid) not in(
select cid ,tid
from pub.teacher_course);








  • 1
    点赞
  • 1
    评论
  • 4
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值