根据学生表,课程表,成绩表,班级表出10道sql语句题
时间: 2023-07-05 08:28:57 浏览: 91
好的,以下是10道 SQL 语句题:
1. 查询学生表中所有学生的信息。
```sql
SELECT * FROM Student;
```
2. 查询班级表中班级名称为“计算机1班”的所有学生信息。
```sql
SELECT * FROM Student WHERE class = '计算机1班';
```
3. 查询学生表中姓“张”的所有学生信息。
```sql
SELECT * FROM Student WHERE name LIKE '张%';
```
4. 查询学生表中年龄大于等于20岁的学生信息。
```sql
SELECT * FROM Student WHERE age >= 20;
```
5. 查询学生表中出生日期在1990年1月1日之后的学生信息。
```sql
SELECT * FROM Student WHERE birthday >= '1990-01-01';
```
6. 查询成绩表中课程编号为1001的学生成绩排名前三的学生姓名和成绩。
```sql
SELECT s.name, g.score
FROM Grade g
JOIN Student s ON g.student_id = s.id
WHERE g.course_id = 1001
ORDER BY g.score DESC LIMIT 3;
```
7. 查询每个班级的平均年龄。
```sql
SELECT class, AVG(age) as avg_age
FROM Student
GROUP BY class;
```
8. 查询每个学院的学生数目。
```sql
SELECT college, COUNT(*) as num_students
FROM Student
GROUP BY college;
```
9. 查询选修了所有课程的学生姓名和学号。
```sql
SELECT s.id, s.name
FROM Student s
WHERE NOT EXISTS (
SELECT c.course_id
FROM Course c
WHERE NOT EXISTS (
SELECT g.student_id
FROM Grade g
WHERE g.course_id = c.course_id AND g.student_id = s.id
)
);
```
10. 查询成绩表中每门课程的平均成绩和最高成绩。
```sql
SELECT course_id, AVG(score) as avg_score, MAX(score) as max_score
FROM Grade
GROUP BY course_id;
```
阅读全文