1. 程式人生 > >關於查詢和"1"號的同學學習的課程完全相同的其他同學的資訊詳細

關於查詢和"1"號的同學學習的課程完全相同的其他同學的資訊詳細

create table bdqn_student(
sno number(2),
sname varchar2(20) not null,
sbirthdate date,
sgender char(2));


comment on column bdqn_student.sno
  is '學員編號';
comment on column bdqn_student.sname
  is '學員姓名';
comment on column bdqn_student.sbirthdate
  is '出生日期';
comment on column bdqn_student.sgender
  is '性別';
 alter table bdqn_student  add constraint pk_student primary key(sno);
 alter table bdqn_student  add constraint ck_student_gender check(sgender in('男','女')); 


create table bdqn_teacher(
tno number(2),
tname varchar2(20) not null);
comment on column bdqn_teacher.tno
  is '教師編號';
comment on column bdqn_teacher.tname
  is '教師姓名';
alter table bdqn_teacher  add constraint pk_teacher primary key(tno);
 
create table bdqn_course(
cno number(2),
cname varchar2(20) not null,
tno number(2));


comment on column bdqn_course.cno
  is '課程編號';
comment on column bdqn_course.cname
  is '課程名稱';
comment on column bdqn_course.tno
  is '教師編號';
alter table bdqn_course  add constraint pk_course primary key(cno);  
alter table bdqn_course add constraint fk_course_tno foreign key(tno) references bdqn_teacher(tno);
  
create table bdqn_score(
sno number(2),
cno number(2),
score number(4,1));


comment on column bdqn_score.sno
  is '學員編號';
comment on column bdqn_score.cno
  is '課程編號';
comment on column bdqn_score.score
  is '成績';
  
alter table bdqn_score  add constraint pk_score primary key(sno,cno);  


alter table bdqn_score add constraint fk_score_sno foreign key(sno) references bdqn_student(sno);
alter table bdqn_score add constraint fk_score_cno foreign key(cno) references bdqn_course(cno);
alter table bdqn_score  add constraint ck_score_score check(score between 0 and 100); 




insert into bdqn_student values(1 , '趙雷' , to_date('1990-01-01','yyyy-mm-dd') , '男');
insert into bdqn_student values(2 , '錢電' , to_date('1990-12-21','yyyy-mm-dd') , '男');
insert into bdqn_student values(3 , '孫風' , to_date('1990-05-20','yyyy-mm-dd') , '男');
insert into bdqn_student values(4 , '李雲' , to_date('1990-08-06','yyyy-mm-dd') , '男');
insert into bdqn_student values(5 , '周梅' , to_date('1991-12-01','yyyy-mm-dd') , '女');
insert into bdqn_student values(6 , '吳蘭' , to_date('1992-03-01','yyyy-mm-dd') , '女');
insert into bdqn_student values(7 , '鄭竹' , to_date('1989-07-01','yyyy-mm-dd') , '女');
insert into bdqn_student values(8 , '王菊' , to_date('1990-01-20','yyyy-mm-dd') , '女');
                                                                              




insert into bdqn_teacher values('1' , '陳璇');
insert into bdqn_teacher values('2' , '蔣紅林');
insert into bdqn_teacher values('3' , '韓露');


insert into bdqn_course values(1 , 'web前端' , 2);
insert into bdqn_course values(2 , 'java基礎' , 1);
insert into bdqn_course values(3 , 'web開發' , 3);
insert into bdqn_score values('01' , '01' , 80);
insert into bdqn_score values('01' , '02' , 90);
insert into bdqn_score values('01' , '03' , 99);
insert into bdqn_score values('02' , '01' , 70);
insert into bdqn_score values('02' , '02' , 60);
insert into bdqn_score values('02' , '03' , 80);
insert into bdqn_score values('03' , '01' , 80);
insert into bdqn_score values('03' , '02' , 80);
insert into bdqn_score values('03' , '03' , 80);
insert into bdqn_score values('04' , '01' , 50);
insert into bdqn_score values('04' , '02' , 30);
insert into bdqn_score values('04' , '03' , 20);
insert into bdqn_score values('05' , '01' , 76);
insert into bdqn_score values('05' , '02' , 87);
insert into bdqn_score values('06' , '01' , 31);
insert into bdqn_score values('06' , '03' , 34);
insert into bdqn_score values('07' , '02' , 89);
insert into bdqn_score values('07' , '03' , 98);


commit;