数据库基础题(求每个班的平均分)

更新时间:2023-05-07 07:23:31 阅读: 评论:0

数据库基础题(求每个班的平均分)
1.创建Account表
create table Account(id int,name varchar(255),class varchar(255));
2.往account⾥插⼊数据
inrt into account values(1,'张三','⾼三⼀班'),(2,'李四','⾼三⼀班'),(3,'王五','⾼三⼆班'),(4,'孙六','⾼三⼆班'); 3.创建exam表
create table exam(id int PRIMARY key,cour VARCHAR(255),score int,aid int);
4.往exam⾥插⼊数据
inrt into exam values(1,'语⽂',90,1),(2,'数学',95,1),(3,'英语',87,1),
(4,'语⽂',70,2),(5,'数学',76,2),(6,'英语',92,2),
(7,'语⽂',75,3),(8,'数学',46,3),(9,'英语',32,3),
(10,'语⽂',84,4),(11,'数学',82,4),(12,'英语',92,4);
5.查看所有数据库
show  batabas;
6.查看所有表
show  tables;
7.查看表结构类型
desc  Account;
desc  eaxm;
8.平均分
SELECT a.class as 班级,e.cour as '考试科⽬', round(AVG(e.score),2) as '平均分' from account a,exam e where a.id=e.aid GROUP BY a.ur

本文发布于:2023-05-07 07:23:31,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/98969.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:查看   数据库   结构   类型   基础
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图