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

Posted weixin_47373497

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了山东大学数据库实验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);








以上是关于山东大学数据库实验3(2021年最新版)的主要内容,如果未能解决你的问题,请参考以下文章

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

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

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

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

山东大学软件学院数据库系统实验——基于华为RDS for MySQL数据库的实验

山东大学软件学院计算机组成原理课程设计整机实验