MySQL学生成绩表查询最大、最小、平均、80分以上、人数、
SELECT * from tb_result;
 set character_set_results = gbk;
 set character_set_server = gbk;
 set character_set_client = gbk;
 set character_set_connection = gbk;
 set character_set_database = gbk;
DROP TABLE IF EXISTS tb_result;
 CREATE TABLE tb_result(
 ?? ?學號 varchar(9) NOT NULL,
 ?? ?姓名 varchar(8) NOT NULL,
 ?? ?性別 varchar(2) NOT NULL,
 ?? ?班級 varchar(7) NOT NULL,
 ?? ?數(shù)學 int(255) not null,
 ?? ?語文 int(255) not null,
 ?? ?英語 int(255) not null,
 ?? ?物理 int(255) not null,
 ?? ?生物 int(255) not null
 ) charset=“utf8”;
INSERT INTO tb_result(學號, 姓名, 性別, 班級,數(shù)學, 語文, 英語, 物理,生物)
 ?VALUES('20220301', '張三', '男','2203', '85', '74', '64', '74', '74'),
 ?? ?('20220302', '李四', '女','2203', '88', '78', '80', '67', '60'),
 ?? ?('20220303', '王五', '男','2204', '90', '80', '84', '82', '80'),
 ?? ?('20220304', '馬六', '女','2204', '85', '76', '78', '84', '68'),
 ?? ?('20220305', '馮七', '女','2204', '78', '80', '65', '80', '65'),
 ?? ?('20220306', '朱八', '男','2204', '88', '85', '68', '78', '70');
-- 檢查表
 SELECT * from tb_result;
?
查詢最大(聚合函數(shù))
 select max(語文) from tb_result;
 select max(語文) as `最大成績`,min(語文) as `最小成績` from tb_result
 查詢最小的(聚合函數(shù))
 select min(語文) from tb_result;
select sum(語文) as `語文總成績`,sum(數(shù)學) as `數(shù)學總成績` from tb_result;
?
查詢男女學生的人數(shù)(分組和聚合函數(shù))
 select count(性別) as `總?cè)藬?shù)` ?from tb_result;
select count(性別) as `男人數(shù)` ?from tb_result where 性別='男';
?按系統(tǒng)計各系學生的平均
 select avg(語文) from tb_result;
 查詢課程平均成績(篩選和聚合函數(shù))
 select avg(語文) as `平均成績` from tb_result where 學號=20220301;
select avg(語文) as `平均成績` from tb_result;
 select avg(語文) as `語文平均成績`,avg(數(shù)學) as `數(shù)學平均成績` from tb_result;
查詢選修課程平均成績在80分以上的學生學號
 SELECT 語文80分以上
 FROM tb_result
 GROUP BY 語文
 HAVING 語文>80;
查詢學號為1001的學生所有課程的總成績(篩選和聚合函數(shù))
 select sum(score) as `總成績` from TbSC where sid=1001;
?
總結(jié)
以上是生活随笔為你收集整理的MySQL学生成绩表查询最大、最小、平均、80分以上、人数、的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Q.me推出! Amortech展示了它
- 下一篇: 服务器系统共享文件,服务器操作系统文件共
