create database school go USE school CREATE TABLE students ( s_no VARCHAR(20) NOT NULL, s_name VARCHAR(20), s_sex CHAR(2), s_birth DATETIME, s_address VARCHAR(30), s_account MONEY, s_password VARCHAR(20) ) CREATE TABLE courses ( c_no CHAR(10), c_name VARCHAR(30), c_date DATETIME, c_credit INT, c_information VARCHAR(50) ) CREATE TABLE enrollment ( s_no VARCHAR(20), c_no CHAR(10), e_score INT, e_date DATETIME, e_register_state CHAR(1), e_check_state CHAR(1), e_test_state CHAR(1) ) INSERT INTO students VALUES('200920001', '张三', '女', '1982-03-24', '北京市', 8200.0, '200920001') INSERT INTO students VALUES('200920006', '吴八', '男', '1972-12-14', '天津市', 5500.0, '200920006') INSERT INTO courses VALUES('22010401', '高等数学', '2009-03-01', 4, '基础课') INSERT INTO courses VALUES('22010410', '人工智能', '2009-03-01', 2, '专业课') INSERT INTO enrollment VALUES('200920001', '22010409', 88, '2009-3-12', '1', '1', '1') INSERT INTO enrollment VALUES('200920001', '22010410', 93, '2009-3-10', '1', '1', '1') 查询平均成绩高于80分的学生的姓名和他们的平均成绩
时间: 2024-01-10 13:02:14 浏览: 47
CreateTable.rar_create table ja_createTab_createTable
好的,根据您提供的 SQL 语句,我可以给出以下查询语句来实现您的需求:
SELECT s_name, AVG(e_score) AS avg_score
FROM students s
JOIN enrollment e ON s.s_no = e.s_no
GROUP BY s_name
HAVING AVG(e_score) > 80;
该查询语句会关联学生表和报名表,计算每个学生的平均成绩,并筛选出平均成绩高于80分的学生,最后返回他们的姓名和平均成绩。
阅读全文