To manage job business training information, create three tables: S (S #, SN, SD, SA) S #, SN, SD, SA stands for student ID, Student name, organization, student age C (C #, CN) C #, CN stands for course number, course name SC (S #, C #, g) S #, C #, and G respectively represent the student ID, number of the selected course, and score 1. query using standard SQL nested statements
To manage job business training information, create three tables: S (S #, SN, SD, SA) S #, SN, SD, SA stands for student ID, Student name, organization, student age C (C #, CN) C #, CN stands for course number, course name SC (S #, C #, g) S #, C #, and G respectively represent the student ID, number of the selected course, and score 1. query using standard SQL nested statements
Create three tables to manage job business training information:
S (S #, SN, SD, SA) S #, SN, SD, and SA represent the student ID, Student name, organization, and student age respectively.
C (C #, CN) C #, CN represents the course number and Course name respectively.
SC (S #, C #, G) S #, C #, and G represent Student IDs, elective course numbers, and academic scores respectively.
1. Use standard SQL nested statements to query the student ID and name of the elective course named 'tax basics'
2. Use standard SQL nested statements to query the name and unit of the student whose elective course number is 'c2'
3. Use standard SQL nested statements to query the names and units of students who do not select the course number as 'c5'
4. Use standard SQL nested statements to query the names and units of trainees who take all courses
5. query the number of students who have selected the course
5. query the number of students who have selected the course
Question 2
Problem description:
Known link mode:
S (SNO, SNAME) Student Relationship. SNO is the student ID, and SNAME is the name
C (CNO, CNAME, CTEACHER) Course relationship. CNO is the course number, CNAME is the course name, And CTEACHER is the course teacher
SC (SNO, CNO, SCGRADE) Course Selection relationship. SCGRADE is the score
1. Find out the names of all students who have not taken the course taught by Mr. Li Ming.
2. List the names and average scores of students whose two or more courses fail.
3. List the names of all students who have learned course 1 and course 2
4. List the student IDs of all students whose scores are higher than those of students whose scores are equal to those of the course No.
5. List the student IDs of all students whose scores are higher than those of Lesson 2 and their scores of Lesson 1 and Lesson 2
Create three tables to manage job business training information:
S (S #, SN, SD, SA) S #, SN, SD, and SA represent the student ID, Student name, organization, and student age respectively.
C (C #, CN) C #, CN represents the course number and Course name respectively.
SC (S #, C #, G) S #, C #, and G represent Student IDs, elective course numbers, and academic scores respectively.
1. Use standard SQL nested statements to query the student ID and name of the elective course named 'tax basics'
-- Implementation code:
Select SN, SD FROM S
Where [S #] IN (
Select [S #] from c, SC
Where C. [C #] = SC. [C #]
And cn = n' tax basis ')
2. Use standard SQL nested statements to query the name and unit of the student whose elective course number is 'c2'
-- Implementation code:
Select S. SN, S. sd from s, SC
Where S. [S #] = SC. [S #]
And SC. [C #] = 'c2'
3. Use standard SQL nested statements to query the names and units of students who do not select the course number as 'c5'
-- Implementation code:
Select SN, SD FROM S
Where [S #] not in (
Select [S #] FROM SC
Where [C #] = 'c5 ')
4. Use standard SQL nested statements to query the names and units of trainees who take all courses
-- Implementation code:
Select SN, SD FROM S
Where [S #] IN (
Select [S #] FROM SC
RIGHT JOIN
C on SC. [C #] = C. [C #] GROUP BY [S #]
Having count (*) = COUNT ([S #])
5. query the number of students who have selected the course
-- Implementation code:
Select students = COUNT (DISTINCT [S #]) FROM SC
6. query the student ID and organization of more than 5 Elective Courses
-- Implementation code:
Select SN, SD FROM S
Where [S #] IN (
Select [S #] FROM SC
Group by [S #]
Having count (DISTINCT [C #])> 5)
Question 2
Problem description:
Known link mode:
S (SNO, SNAME) Student Relationship. SNO is the student ID, and SNAME is the name
C (CNO, CNAME, CTEACHER) Course relationship. CNO is the course number, CNAME is the course name, And CTEACHER is the course teacher
SC (SNO, CNO, SCGRADE) Course Selection relationship. SCGRADE is the score
1. Find out the names of all students who have not taken the course taught by Mr. Li Ming.
-- Implementation code:
Select sname from s where sno in
(Select sno from SC, c where SC. cno = c. cno and c. cteachere = "Li Ming ")
Select SNAME FROM S
Where not exists (
Select * from SC, C
Where SC. CNO = C. CNO
And cname = 'lilim'
And SC. SNO = S. SNO)
2. List the names and average scores of students whose two or more courses fail.
-- Implementation code:
Select S. SNO, S. SNAME, AVG_SCGRADE = AVG (SC. SCGRADE)
From s, SC ,(
Select SNO
FROM SC
Where SCGRADE <60
GROUP BY SNO
Having count (distinct cno)> = 2
) A Where S. SNO = A. sno and SC. SNO = A. SNO
Group by s. SNO, S. SNAME
3. List the names of all students who have learned course 1 and course 2
-- Implementation code:
Select S. SNO, S. SNAME
From s ,(
Select SC. SNO
From SC, C
Where SC. CNO = C. CNO
And c. cname in ('1', '2 ')
GROUP BY SNO
Having count (distinct cno)> = 2
) SC Where S. SNO = SC. SNO
4. List the student IDs of all students whose scores are higher than those of students whose scores are equal to those of the course No.
-- Implementation code:
Select SC. sno from SC,
(Select sc1.sno from
(Select SC. sno, SC. scgrade from SC, c where SC. cno = c. cno and c. cname = '1') sc1,
(Select SC. sno, SC. scgrade from SC, c where SC. cno = c. cno and c. cname = '1') sc2,
Where sc1.sno = sc2.sno and sc1.sgrade> sc2.scgrade
) Scc
Where SC. sno = scc. sno
Select S. SNO, S. SNAME
From s ,(
Select SC1.SNO
From SC SC1, C C1, SC SC2, C C2
Where SC1.CNO = C1.CNO AND C1.NAME = '1'
AND SC2.CNO = C2.CNO AND C2.NAME = '2'
AND SC1.SCGRADE> SC2.SCGRADE
) SC Where S. SNO = SC. SNO
5. List the student IDs of all students whose scores are higher than those of Lesson 2 and their scores of Lesson 1 and Lesson 2
-- Implementation code:
Select S. SNO, S. SNAME, SC. [score of Lesson 1], SC. [score of Lesson 2]
From s ,(
Select SC1.SNO, [score for Lesson 1] = SC1.SCGRADE, [score for Lesson 2] = SC2.SCGRADE
From SC SC1, C C1, SC SC2, C C2
Where SC1.CNO = C1.CNO AND C1.NAME = '1'
AND SC2.CNO = C2.CNO AND C2.NAME = '2'
AND SC1.SCGRADE> SC2.SCGRADE
) SC Where S. SNO = SC. SNO