2024-11-25 10:01:50
需要用group by语句来统计。
1、创建测试表、插入数据:
create table test
(id int,
name varchar(10),
score int,
classname varchar(20));
insert into test values (1,'张三',100,'一班');
insert into test values (2,'李四',89,'一班');
insert into test values (3,'王五',97,'一班');
insert into test values (4,'赵六',87,'二班');
insert into test values (5,'孙七',94,'二班');
insert into test values (6,'杨八',76,'二班');
2、查询每个班级的总分,可用如下语句:
select classname,SUM(score) as 总分 from test group by classname;
3、结果截图:
2024-11-25 09:33:54