查询选修了学号 20131322001 同学所选修全部课程的学生姓名、学号、课程名
时间: 2023-11-24 17:53:33 浏览: 237
以下是查询选修了学号 20131322001 同学所选修全部课程的学生姓名、学号、课程名的SQL语句:
```sql
SELECT s.学号, s.姓名, c.课程名称
FROM 学生 s, 课程 c, 选课记录 r
WHERE s.学号 = r.学号 AND c.课程代码 = r.课程代码 AND c.课程代码 IN (
SELECT 课程代码
FROM 选课记录
WHERE 学号 = '20131322001'
)
GROUP BY s.学号, s.姓名, c.课程名称
HAVING COUNT(DISTINCT c.课程代码) = (
SELECT COUNT(DISTINCT 课程代码)
FROM 选课记录
WHERE 学号 = '20131322001'
)
```
相关问题
--⒅ 查询选修了学号为20121323001的同学所选修的全部课程的学生姓名、学号、课程名。
以下是查询选修了学号为20121323001的同学所选修的全部课程的学生姓名、学号、课程名的SQL语句:
```
SELECT s.学号, s.姓名, c.课程名
FROM 学生 s, 课程 c, 选课记录 r
WHERE s.学号 = r.学号 AND c.课程代码 = r.课程代码 AND r.学号 = '20121323001';
```
根据上面的对话检索“程军”老师所授课程的课程号和课程名。 (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);
```
阅读全文