CREATE TABLE Student(
stid VARCHAR2(10) PRIMARY KEY,
sname VARCHAR2(20),
sage NUMBER(2),
sgender VARCHAR2(5)
);
CREATE TABLE Teacher(
tid VARCHAR2(10) PRIMARY KEY,
tname VARCHAR2(20)
);
CREATE TABLE Course(
cid VARCHAR2(10),
cname VARCHAR2(20),
tid VARCHAR2(10),
CONSTRAINT pk_course PRIMARY KEY (cid,tid)
);
CREATE TABLE SC(
stid VARCHAR2(10),
cid VARCHAR2(10),
score NUMBER(4,2),
CONSTRAINT pk_sc PRIMARY KEY (stid,cid)
);
insert into Student values ('s001','张三',23,'男');
insert into Student values ('s002','李四',23,'男');
insert into Student values ('s003','吴鹏',25,'男');
insert into Student values ('s004','琴沁',20,'女');
insert into Student values ('s005','王丽',20,'女');
insert into Student values ('s006','李波',21,'男');
insert into Student values ('s007','刘玉',21,'男');
insert into Student values ('s008','萧蓉',21,'女');
insert into Student values ('s009','陈萧晓',23,'女');
insert into Student values ('s010','陈美',22,'女');
COMMIT;
insert into Teacher values ('t001', '刘阳');
insert into Teacher values ('t002', '谌燕');
insert into Teacher values ('t003', '胡明星');
insert into Teacher values ('t004', '胡青青');
COMMIT;
insert into Course values ('c001','J2SE','t002');
insert into Course values ('c002','Java Web','t002');
insert into Course values ('c003','SSH','t001');
insert into Course values ('c004','Oracle','t001');
insert into Course values ('c005','SQL SERVER 2005','t003');
insert into Course values ('c006','C#','t003');
insert into Course values ('c007','JavaScript','t002');
insert into Course values ('c008','DIV+CSS','t001');
insert into Course values ('c009','PHP','t003');
insert into Course values ('c010','EJB3.0','t002');
commit;
insert into sc values ('s001','c001',78.9);
insert into sc values ('s002','c001',80.9);
insert into sc values ('s003','c001',81.9);
insert into sc values ('s004','c001',60.9);
insert into sc values ('s001','c002',82.9);
insert into sc values ('s002','c002',72.9);
insert into sc values ('s003','c002',81.9);
insert into sc values ('s001','c003','59');
commit;
SELECT stid,AVG(score) FROM sc GROUP BY stid HAVING AVG(score)>70
SELECT COUNT(*) FROM teacher WHERE tname LIKE '胡%'
SELECT s.stid,s.sname,COUNT(sc.cid),SUM(sc.score) FROM student s,sc sc WHERE s.stid=sc.stid GROUP BY s.stid,s.sname
SELECT a.stid FROM (SELECT stid,score FROM sc WHERE cid='c001') a,(SELECT stid,score FROM sc WHERE cid='c002') b WHERE a.score>b.score AND a.stid=b.stid
SELECT s.stid,s.sname FROM student s WHERE s.stid NOT IN(
SELECT s.stid FROM student s,sc sc,course c,teacher t WHERE s.stid=sc.stid AND sc.cid=c.cid AND c.tid=t.tid AND t.tname='刘阳')
SELECT s.stid,s.sname FROM student s,(SELECT stid FROM sc WHERE cid='c001') a,(SELECT stid FROM sc WHERE cid='c002') b WHERE a.stid=b.stid AND s.stid=a.stid
SELECT s.stid,s.sname FROM student s WHERE s.stid NOT IN(SELECT DISTINCT(sc.stid) FROM student s,sc sc WHERE s.stid=sc.stid AND sc.score>60)
SELECT s.stid,s.sname FROM student s,course c,sc sc WHERE s.stid=sc.stid AND sc.cid=c.cid AND c.cname='J2SE'
SELECT sname,sgender FROM student WHERE stid NOT IN (SELECT stid FROM sc WHERE cid='c001')
SELECT s.sname,s.sgender FROM student s,course c,sc sc WHERE s.stid=sc.stid AND sc.cid=c.cid GROUP BY s.sname,s.sgender HAVING COUNT(c.cid)>2