用SQL语言表示“检索全部学生都选修的课程的课程号和课程名”,其中学生姓名、学号在S表中,学号、课程号在SC表中,课程号和课程名在C表中
时间: 2024-06-10 09:06:11 浏览: 209
答案是:
SELECT c.cno, c.cname
FROM c
WHERE NOT EXISTS (
SELECT s.sno
FROM s
WHERE NOT EXISTS (
SELECT sc.cno
FROM sc
WHERE sc.sno = s.sno
AND sc.cno = c.cno
)
);
相关问题
用SQL语言表示“检索全部学生都选修的课程的课程号和课程名”,其中学号、课程号在SC表中,课程号和课程名在C表中
SELECT C.课程号, C.课程名
FROM C
WHERE NOT EXISTS (SELECT *
FROM SC
WHERE SC.课程号 = C.课程号
AND SC.学号 NOT IN (SELECT 学号
FROM SC
WHERE SC.课程号 = C.课程号));
根据上面的对话检索“程军”老师所授课程的课程号和课程名。 (3)检索年龄大于19岁男学生的学号和姓名。 (4)检索“李勇”同学不学课程的课程号。 (5)检索至少选修两门课程的学生学号。 (6)检索选修课程号为1和2的学生学号。 (7)检索至少选修“程军”老师所授全部课程的学生姓名。 (8)检索选修课程包含学号为201215122的学生所修课程的学生学号。 (9)检索全部学生都选修的课程的课程号和课程名。 (10)检索选修全部课程的学生姓名。 (11)查询所在系是CS系的学生选修的课程的课程名和学分,结果按课程名降序排序。 (12)检索“数据库”课程成绩高于90分的所有学生的学号、姓名和分数. (13)查询男生和女生选修课程的平均成绩。 (14)检索没有选课的学生的学号和姓名。 (15)检索没有任何一门课程成绩不及格的学生的信息,包括学号、姓名
很抱歉,作为语言模型,我不能直接连接数据库进行数据检索。但是,我可以提供一些 SQL 查询语句的示例,您可以根据这些示例进行相应的查询操作:
1. 检索“程军”老师所授课程的课程号和课程名:
```
SELECT Cno, Cname
FROM Course
WHERE Cpno IN (SELECT Cno FROM Course WHERE Cname = '程军');
```
2. 检索年龄大于19岁男学生的学号和姓名:
```
SELECT Sno, Sname
FROM Student
WHERE Ssex = '男' AND Sage > 19;
```
3. 检索“李勇”同学不学课程的课程号:
```
SELECT Cno
FROM Course
WHERE Cno NOT IN (SELECT Cno FROM SC WHERE Sno = (SELECT Sno FROM Student WHERE Sname = '李勇'));
```
4. 检索至少选修两门课程的学生学号:
```
SELECT Sno
FROM SC
GROUP BY Sno
HAVING COUNT(*) >= 2;
```
5. 检索选修课程号为1和2的学生学号:
```
SELECT Sno
FROM SC
WHERE Cno IN ('1', '2');
```
6. 检索至少选修“程军”老师所授全部课程的学生姓名:
```
SELECT Sname
FROM Student
WHERE Sno IN (SELECT Sno FROM SC WHERE Cno IN (SELECT Cno FROM Course WHERE Cpno IN (SELECT Cno FROM Course WHERE Cname = '程军'))
GROUP BY Sno
HAVING COUNT(*) = (SELECT COUNT(*) FROM Course WHERE Cpno IN (SELECT Cno FROM Course WHERE Cname = '程军')));
```
7. 检索选修课程包含学号为201215122的学生所修课程的学生学号:
```
SELECT DISTINCT Sno
FROM SC
WHERE Cno IN (SELECT Cno FROM SC WHERE Sno = '201215122');
```
8. 检索全部学生都选修的课程的课程号和课程名:
```
SELECT Cno, Cname
FROM Course
WHERE Cno IN (SELECT Cno FROM SC GROUP BY Cno HAVING COUNT(*) = (SELECT COUNT(*) FROM Student));
```
9. 检索选修全部课程的学生姓名:
```
SELECT Sname
FROM Student
WHERE Sno IN (SELECT Sno FROM SC GROUP BY Sno HAVING COUNT(*) = (SELECT COUNT(*) FROM Course));
```
10. 查询所在系是CS系的学生选修的课程的课程名和学分,结果按课程名降序排序:
```
SELECT C.Cname, C.Ccreadit
FROM SC AS S
JOIN Course AS C ON S.Cno = C.Cno
JOIN Student AS St ON S.Sno = St.Sno
WHERE St.Sdept = 'CS'
ORDER BY C.Cname DESC;
```
11. 检索“数据库”课程成绩高于90分的所有学生的学号、姓名和分数:
```
SELECT S.Sno, S.Sname, SC.Grade
FROM Student AS S
JOIN SC ON S.Sno = SC.Sno
JOIN Course AS C ON SC.Cno = C.Cno
WHERE C.Cname = '数据库' AND SC.Grade > 90;
```
12. 查询男生和女生选修课程的平均成绩:
```
SELECT S.Ssex, AVG(SC.Grade) AS AvgGrade
FROM Student AS S
JOIN SC ON S.Sno = SC.Sno
GROUP BY S.Ssex;
```
13. 检索没有选课的学生的学号和姓名:
```
SELECT S.Sno, S.Sname
FROM Student AS S
WHERE S.Sno NOT IN (SELECT Sno FROM SC);
```
14. 检索没有任何一门课程成绩不及格的学生的信息,包括学号、姓名:
```
SELECT S.Sno, S.Sname
FROM Student AS S
WHERE S.Sno NOT IN (SELECT Sno FROM SC WHERE Grade < 60);
```
阅读全文