查询学号为“10002”的学生的所有成绩,结果需包含学号、姓名、所在系别、课程号、课程名及对应成绩。 (2) 查询每位学生成绩大于85的课程,结果需包含学号、姓名、所在系别
时间: 2024-09-27 08:16:01 浏览: 69
SQL数据查询——综合练习(一)
5星 · 资源好评率100%
在数据库查询中,要获取特定学生的信息和满足条件的成绩,通常会涉及到两个SQL查询:
1. **查询学号为“10002”的学生所有成绩**
```sql
SELECT students.id AS 学号, students.name AS 姓名, departments.department_name AS 所在系别,
courses.course_code AS 课程号, courses.course_name AS 课程名, grades.score AS 成绩
FROM students
JOIN student_departments ON students.id = student_departments.student_id
JOIN departments ON student_departments.department_id = departments.id
JOIN courses ON courses.id = students.courses_taken_id
WHERE students.id = '10002';
```
2. **查询每位学生成绩大于85的课程信息**
```sql
SELECT students.id AS 学号, students.name AS 姓名, departments.department_name AS 所在系别
FROM students
JOIN student_departments ON students.id = student_departments.student_id
JOIN departments ON student_departments.department_id = departments.id
WHERE students.id IN (
SELECT student_id
FROM grades
WHERE score > 85
);
```
阅读全文