数据库基础题(求每个班的平均分)
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