1. Table structure
-- create table Timetable Create table t_course ( cno varchar2 (), cname varchar2 (, ) creatdate char (Ten), updatedate char ()) tablespace users pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K next 1M minextents 1 maxextents unlimited );-- create table Student table create Table t_student (  SNO   VARCHAR2), sname varchar2 (, ) sage number) tablespace users pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K next 1m minextents 1 maxextents unlimited );-- Create table Student and Curriculum Association table Create table t_student_course ( sno   VARCHAR2 (+),   CNO     VARCHAR2 (, score ) number (15,2), ischeat number) tablespace users pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K next 1M minextents 1 maxextents unlimited );
Two: Table data
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 programming ', null, null);insert into t_course (Cno, cname, creatdate, updatedate) values (' c1002 ', ' math ', null, null);insert into t_course ( cno, cname, creatdate, updatedate) values (' c1003 ', ' English ', null, null); insert into t_course (cno, cname, creatdate, updatedate) values (' c1004 ', ' SQL Programming ', null, null);insert into t_course (cno, cname, creatdate, updatedate) values (' c1005 ', ' language ', null, null);insert into t_course (cno, cname, creatdate, updatedate) values (' c1006 ', ' Java algorithm ', ' 2010-10-30 ', null); Insert into T_COURSE (cno, cname, creatdate, updatedate) values (' c1007 ', ' algorithmic design ', ' 2017-10-30 ', null);insert into t_course (cno, cname, creatdate, updatedate ) values (' c1008 ', ' physics ', 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: Problems and SQL statements
--1. Name and student number of all participants in the designated course Select ts.sno,ts.sname,tc.cname from t_student_course tsc inner join t_course tc on tc.cno=tsc.cnoinner join t_student ts on ts.sno=tsc.snowhere tc.cname= ' Java programming '--2. Specify course and age greater than 20select count (1) Sum from t_student_course tsc inner join t_course tc on tc.cno=tsc.cnoinner join t_student ts on ts.sno=tsc.snowhere tc.cname= ' algorithmic design ' and ts.sage >20--3. Query elective courses more than 5 student number, name --method one Select ts.sno,ts.sname from t_student_course tsc left join t_course tc on tc.cno=tsc.cnoleft join t_student ts on ts.sno=tsc.snogroup by ts.sno ,ts.snamehaving count (*) >5 --method Two Select ts.sno,ts.sname from t _student tswhere ts.sno In (Select tsc.sno from t_student_course tscgroup by tsc.snohaving count ( Distinct (TSC.CNO)) >5)--4. Modify T_student_course table Ischeat to 0 student scores updated to 0UPDATE&NBSP;T_STUDENT_COURSE&NBSP;&NBSP;TSC set tsc.score=0 where tsc.ischeat=0 --5. The student who ischeat 0 in the T_student_course table from T_ Student Delete Delete from t_student ts where ts.sno in in table ( select tsc.sno from t_student_course tsc where tsc.ischeat=0 )--6. Check all course scores less than 60 points without cheating student number, student name, score Select * from t_student_course tscleft join t_ Student ts on tsc.sno=ts.snowhere tsc.score<60 and tsc.ischeat=1
SQL Face question