课外天地 李树青学习天地数据库系统原理课件 → 课上所讲的关系笛卡尔乘积练习参考脚本(Oracle)


  共有20990人关注过本帖树形打印复制链接

主题:课上所讲的关系笛卡尔乘积练习参考脚本(Oracle)

帅哥哟,离线,有人找我吗?
admin
  1楼 博客 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 管理员
等级:管理员 帖子:1945 积分:26736 威望:0 精华:34 注册:2003/12/30 16:34:32
课上所讲的关系笛卡尔乘积练习参考脚本(Oracle)  发帖心情 Post By:2009/9/18 18:17:39 [只看该作者]

1、数据准备
CREATE TABLE student
(
"NUMBER" varchar2(6) NOT NULL,
name varchar2(8) NULL,
sex number(1),
birthday timestamp NULL,
height number(3,2) NULL
);

insert into student ("NUMBER",name,sex,birthday,height)  values ( '000001','黎明',1,TO_DATE('15-4月 -1980','dd-Mon-
yyyy'),1.78);
insert into student ("NUMBER",name,sex,birthday,height)  values ( '000002','赵怡春',0,TO_DATE('17-12月 -1982','dd-Mon-
yyyy'),1.77);
insert into student ("NUMBER",name,sex,birthday,height)  values ( '000003','张富平',1,TO_DATE('1-2月 -1981','dd-Mon-
yyyy'),1.80);
insert into student ("NUMBER",name,sex,birthday,height)  values ( '000004','白丽',0,TO_DATE('20-11月 -1986','dd-Mon-
yyyy'),1.73);
insert into student ("NUMBER",name,sex,birthday,height)  values ( '000005','牛玉德',1,TO_DATE('1-5月 -1983','dd-Mon-
yyyy'),1.74);
insert into student ("NUMBER",name,sex,birthday,height)  values ( '000006','姚华',0,TO_DATE('12-5月 -1983','dd-Mon-
yyyy'),1.77);

CREATE TABLE grade
(
  "NUMBER" varchar2(6) NULL,
course varchar2(50) NULL,
grade number(3) NULL
);

insert into grade ("NUMBER",course,grade) values ('000001','A03',56);
insert into grade ("NUMBER",course,grade) values ('000002','A02',90);
insert into grade ("NUMBER",course,grade) values ('000004','A02',77);
insert into grade ("NUMBER",course,grade) values ('000005','B01',91);
insert into grade ("NUMBER",course,grade) values ('000004','A03',76);
insert into grade ("NUMBER",course,grade) values ('000003','A03',67);
insert into grade ("NUMBER",course,grade) values ('000001','B01',78);
insert into grade ("NUMBER",course,grade) values ('000002','A03',74);
insert into grade ("NUMBER",course,grade) values ('000002','B01',86);
insert into grade ("NUMBER",course,grade) values ('000003','A02',80);
insert into grade ("NUMBER",course,grade) values ('000004','B01',90);

2、简单的关系笛卡尔乘积
select * from student,grade

带有选择的结果
select * from student,grade where student.number=grade.number

3、查询黎明所选修的课程成绩
select course,grade from grade where number=(select number from student where name='黎明')


 

[此贴子已经被作者于2010-12-11 20:07:42编辑过]

 回到顶部