查询平均成绩大于等于60分的同学的学生编号和学生姓名和平均成绩create table Student(s_id varchar(100),s_name varchar(200),s_birth date,s_sex varchar(100)); create table Course(c_id varchar(100),c_name varchar(200),t_id varchar(100)); insert into Course values('01','语文','02'); insert into Course values('02','数学','01'); insert into Course values('03','英语','03'); insert into student values('01','赵雷','1990-01-01','男'); insert into student values('02','钱电','1990-12-21','男'); insert into student values('03','孙风','1990-05-20','男'); insert into student values('04','李云','1990-08-06','男'); insert into student values('05','周梅','1991-12-01','女'); insert into student values('06','吴兰','1992-03-01','女'); insert into student values('07','郑竹','1989-07-01','女'); insert into student values('08','王菊','1990-01-20','女'); create table Teacher(t_id varchar(100),t_name varchar(100)); create table Score (s_id varchar(100), c_id varchar(100),s_score int); insert into score values('01','01',80); insert into score values('01','02',90); insert into score values('01','03',99); insert into score values('02','01',70); insert into score values('02','02',60); insert into score values('02','03',80); insert into score values('03','01',80); insert into score values('03','02',80); insert into score values('03','03',80); insert into score values('04','01',50); insert into score values('04','02',30); insert into score values('04','03',20); insert into score values('05','01',76); insert into score values('05','02',87); insert into teacher values('01','张三'); insert into teacher values('02','李四'); insert into teacher values('03','王五');
时间: 2023-03-29 18:04:15 浏览: 136
我可以回答这个问题。查询平均成绩大于等于60分的同学的学生编号和学生姓名和平均成绩的 SQL 语句如下:
SELECT s_id, s_name, AVG(s_score) AS avg_score
FROM student, score
WHERE student.s_id = score.s_id
GROUP BY student.s_id, student.s_name
HAVING AVG(s_score) >= 60;
相关问题
利用mysql创建学生表, 查询每个学生的平均成绩 显示效果 学生编号 学生姓名 平均成绩
好的,那我们首先需要在MySQL中创建一个学生表,并且在该表中插入学生的成绩记录和学生信息。以下是一个示例的MySQL表的创建语句:
```
CREATE TABLE student (
id INT PRIMARY KEY,
name VARCHAR(50),
score INT
);
INSERT INTO student VALUES
(1, '张三', 80),
(1, '张三', 90),
(1, '张三', 70),
(2, '李四', 85),
(2, '李四', 95),
(2, '李四', 75),
(3, '王五', 90),
(3, '王五', 85),
(3, '王五', 95);
```
以上是一个简单的学生表的创建和数据插入的示例。接下来,我们可以使用下面的SQL语句查询每个学生的平均成绩,并且按照学生编号升序排列:
```
SELECT id, name, AVG(score) AS average_score FROM student GROUP BY id ORDER BY id ASC;
```
执行上面的SQL语句后,你会得到如下的结果:
```
+----+--------+---------------+
| id | name | average_score |
+----+--------+---------------+
| 1 | 张三 | 80.0000 |
| 2 | 李四 | 85.0000 |
| 3 | 王五 | 90.0000 |
+----+--------+---------------+
```
以上结果展示了每个学生的编号、姓名和平均成绩。
成绩表 create table course ( sid varchar(16),--学号 cid varchar(32),--课程编号 score int---成绩 ) 查询成绩大于85分的学生姓名
根据您提供的成绩表,以下是查询成绩大于85分的学生姓名的 SQL 语句:
SELECT DISTINCT student.name
FROM student, course
WHERE student.sid = course.sid AND course.score > 85;
请注意,这是一个 SQL 查询语句,用于从数据库中检索数据。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)