标签:没有 ctf 表结构 init heat 物理 超过 create 课程
1.表结构-- Create table 课程表 create table T_COURSE ( cno VARCHAR2(20), cname VARCHAR2(20), creatdate CHAR(10), updatedate CHAR(10) ) tablespace USERS pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K next 1M minextents 1 maxextents unlimited ); -- Create table 学生表 create table T_STUDENT ( sno VARCHAR2(20), sname VARCHAR2(20), sage NUMBER ) tablespace USERS pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K next 1M minextents 1 maxextents unlimited ); -- Create table 学生与课程关联表 create table T_STUDENT_COURSE ( sno VARCHAR2(64), cno VARCHAR2(64), score NUMBER(15,2), ischeat NUMBER ) tablespace USERS pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K next 1M minextents 1 maxextents unlimited );
二:表数据
insert into T_STUDENT (SNO, SNAME, SAGE) values ('s1001', 'JITION', 50); insert into T_STUDENT (SNO, SNAME, SAGE) values ('s1002', 'CQS', 13); insert into T_STUDENT (SNO, SNAME, SAGE) values ('s1003', 'CAO', 30); insert into T_STUDENT (SNO, SNAME, SAGE) values ('s1004', 'QI', 15); insert into T_STUDENT (SNO, SNAME, SAGE) values ('s1005', 'SHUN', 30); -- insert into T_COURSE (CNO, CNAME, CREATDATE, UPDATEDATE) values ('c1001', 'JAVA程序设计', null, null); insert into T_COURSE (CNO, CNAME, CREATDATE, UPDATEDATE) values ('c1002', '数学', null, null); insert into T_COURSE (CNO, CNAME, CREATDATE, UPDATEDATE) values ('c1003', '英语', null, null); insert into T_COURSE (CNO, CNAME, CREATDATE, UPDATEDATE) values ('c1004', 'SQL程序设计', null, null); insert into T_COURSE (CNO, CNAME, CREATDATE, UPDATEDATE) values ('c1005', '语文', null, null); insert into T_COURSE (CNO, CNAME, CREATDATE, UPDATEDATE) values ('c1006', 'JAVA算法', '2010-10-30', null); insert into T_COURSE (CNO, CNAME, CREATDATE, UPDATEDATE) values ('c1007', '算法设计', '2017-10-30', null); insert into T_COURSE (CNO, CNAME, CREATDATE, UPDATEDATE) values ('c1008', '物理', null, null); -- insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1001', 'c1001', 36.00, 1); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1001', 'c1002', 72.00, 1); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1002', 'c1001', 100.00, 1); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1002', 'c1003', 0.00, 0); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1003', 'c1011', 0.00, 0); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1004', 'c1001', 90.00, 1); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1004', 'c1003', 80.00, 1); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1001', 'c1007', 0.00, 0); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1002', 'c1007', 90.00, 1); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1003', 'c1007', 85.00, 1); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1004', 'c1007', 0.00, 0); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1005', 'c1007', 96.00, 1); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1001', 'c1004', 80.00, 1); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1001', 'c1003', 80.00, 1); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1001', 'c1005', 90.00, 1); insert into T_STUDENT_COURSE (SNO, CNO, SCORE, ISCHEAT) values ('s1001', 'c1006', 80.00, 1);
3:问题及sql语句
--1.指定课程所有学员姓名和学号 select ts.sno,ts.sname,tc.cname from t_student_course tsc inner join T_COURSE tc on tc.cno=tsc.cno inner join t_Student ts on ts.sno=tsc.sno where tc.cname='JAVA程序设计' --2.指定课程并且年龄大于20 select count(1) "求和" from t_student_course tsc inner join T_COURSE tc on tc.cno=tsc.cno inner join t_Student ts on ts.sno=tsc.sno where tc.cname='算法设计' and ts.sage>20 --3.查询选修课程超过5门的学生学号、姓名 --方法一 select ts.sno,ts.sname from t_student_course tsc left join T_COURSE tc on tc.cno=tsc.cno left join t_Student ts on ts.sno=tsc.sno GROUP BY ts.sno ,ts.sname having count(*)>5 --方法二 select ts.sno,ts.sname from t_student ts where ts.sno in( select tsc.sno FROM t_student_course tsc GROUP BY tsc.sno having count(Distinct(tsc.cno))>5 ) --4.修改t_student_course表中ISCheat为0的学生成绩更新为0 update t_student_course tsc set tsc.score=0 where tsc.ischeat=0 --5.将t_student_course表中ISCheat为0的学生从t_student表中删除 delete from t_student ts where ts.sno in( select tsc.sno from t_student_course tsc where tsc.ischeat=0 ) --6.查询所有课程分数小于60分且没有作弊的学生号,学生姓名,分数 select * from t_student_course tsc left join t_student ts on tsc.sno=ts.sno where tsc.score<60 and tsc.ischeat=1
标签:没有 ctf 表结构 init heat 物理 超过 create 课程
原文地址:http://blog.51cto.com/1929297/2057128