用sql做下列题目(1)查询所有女生的平均年龄。 (2)查询刘老师所授课程的选课学生姓名。 (3)查询张老师所授课程中,选课人数超过10人的课程信息。 (4)查询卢老师所授课程中,选课人数最多的课程的课程号,课程名称和选课人数。 (5)查询每个同学的平均分数,以平均分数降序排列,显示前5名。 (6)查询姓“张”的同学平均成绩前三的学生学号和姓名及平均分; (7) 查询女生平均分超过85分的学生人数。 (8)查询男生平均分超过85的学生姓名。 (9)查询与“张三丰”在一个系的同学姓名。 (10)查询所有老师中,上课门数最多的老师姓名和职称。
时间: 2024-02-22 18:01:01 浏览: 115
很高兴为您回答这个问题,以下是每个问题对应的SQL查询语句:
(1)
```
SELECT AVG(age) FROM students WHERE gender='女';
```
(2)
```
SELECT students.name FROM students,courses,teachers WHERE students.id=courses.sid AND courses.tid=teachers.id AND teachers.name='刘老师';
```
(3)
```
SELECT courses.cid,courses.name,COUNT(courses.sid) as count FROM courses,teachers WHERE courses.tid=teachers.id AND teachers.name='张老师' GROUP BY courses.cid,courses.name HAVING COUNT(courses.sid)>10;
```
(4)
```
SELECT courses.cid,courses.name,COUNT(courses.sid) as count FROM courses,teachers WHERE courses.tid=teachers.id AND teachers.name='卢老师' GROUP BY courses.cid,courses.name ORDER BY count DESC LIMIT 1;
```
(5)
```
SELECT students.id,students.name,AVG(score) as avg_score FROM students,scores WHERE students.id=scores.sid GROUP BY students.id ORDER BY avg_score DESC LIMIT 5;
```
(6)
```
SELECT students.id,students.name,AVG(score) as avg_score FROM students,scores WHERE students.id=scores.sid AND students.name LIKE '张%' GROUP BY students.id ORDER BY avg_score DESC LIMIT 3;
```
(7)
```
SELECT COUNT(DISTINCT students.id) FROM students,scores WHERE students.id=scores.sid AND students.gender='女' GROUP BY students.id HAVING AVG(score)>85;
```
(8)
```
SELECT students.name FROM students,scores WHERE students.id=scores.sid AND students.gender='男' GROUP BY students.id HAVING AVG(score)>85;
```
(9)
```
SELECT students.name FROM students WHERE students.department=(SELECT department FROM students WHERE students.name='张三丰');
```
(10)
```
SELECT teachers.name,teachers.title,COUNT(courses.tid) as course_num FROM teachers,courses WHERE teachers.id=courses.tid GROUP BY teachers.id ORDER BY course_num DESC LIMIT 1;
```
请注意,这些SQL查询语句是根据假设的数据库表结构编写的,如果您的表结构不同,这些查询语句可能需要进行适当的修改。
阅读全文