SELECT Sname, Sage, Ssex FROM Student WHERE Sid IN (SELECT Sid FROM SC WHERE Cid=1 AND score>80),
时间: 2024-06-01 12:10:43 浏览: 145
This SQL query selects the names, ages, and genders of all students who have taken Course 1 and scored above 80. The subquery selects the student IDs of those who have taken Course 1 and scored above 80, and these IDs are used to filter the results from the Student table.
The resulting table will have three columns: Sname (student name), Sage (student age), and Ssex (student gender).
相关问题
有以下四张表: 1).学生表 Student(SID,Sname,Sage,Ssex) --SID 学生编号,Sname 学生姓名,Sage 出生年月,Ssex 学生性别 2).课程表 Course(CID,Cname,TID) --CID --课程编号,Cname 课程名称,TID 教师编号 3).教师表 Teacher(TID,Tname) --TID 教师编号,Tname 教师姓名 4).成绩表 SC(SID,CID,score) --SID 学生编号,CID 课程编号,score 分数 请写出以下
SQL语句:
1. 查询所有学生的姓名、年龄和性别:
```
SELECT Sname, Sage, Ssex FROM Student;
```
2. 查询所有课程的名称和对应的教师姓名:
```
SELECT Cname, Tname FROM Course, Teacher WHERE Course.TID = Teacher.TID;
```
3. 查询所有选修了某门课程的学生的姓名和成绩:
```
SELECT Student.Sname, SC.score FROM Student, SC WHERE Student.SID = SC.SID AND SC.CID = '某门课程编号';
```
4. 查询某个学生的所有成绩及其对应的课程名称:
```
SELECT Course.Cname, SC.score FROM Course, SC WHERE Course.CID = SC.CID AND SC.SID = '某个学生编号';
```
学生表Student(Sid, Sname, Sage, Ssex) Sid 学生编号, Sname 学生姓名, Sage 出生年月, Ssex学生性别--2.课程表Course(Cid, Cname, Tid) Cid 课程编号, Cname 课程名称, Tid 教师编号--3.教师表Teacher(Tid, Tname) Tid 教师编号, Tname 教师姓名--4.成绩表SC(Sid, Cid, score) Sid 学生编号, Cid 课程编号, score 分数 查询每门课程的平均成绩,结果按平均成绩降序排列,平均成绩相同时,按课程编号升序排列/////
可以回答这个问题。查询语句如下:
SELECT Cname, AVG(score) AS avg_score
FROM Course, SC
WHERE Course.Cid = SC.Cid
GROUP BY Course.Cid
ORDER BY avg_score DESC, Course.Cid ASC;
阅读全文