MySQL之聚合查询


  • 将现有的多行数据进行统计,只能看到结果
  • count(): 计算总行数,括号中写星与列名,结果是相同的*
  • 查询学生总数
select count(*) from students;
  • max(列): 表示此列的最大值
  • 查询女生编号的最大值
select max(id) from students where gender=0;
  • min(列): 表示此列的最小值
  • 查询 未删除的学生最小编号
select min(id) from students where isDelete=0;
  • 子查询
  • 查询 未删除的学生最小编号 的信息
select * from students where id=(select min(id) from students where isDelete=0);
  • sum(列): 求此列的和
  • 查询 男生编号 的和
select * from students where gender=1;
  • avg(列):求此列的平均值
  • 查询 未删除的女生编号的平均值
select avg(id) from students where gender=0 and isDelete=0;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章