聚合
为了快速统计数据,提供了5个聚合函数:

count(*)
表示计算总的行数,括号中写 * 与列名,其结果相同
例:

select count(*) from students;
select count(*) from students where isdelete=1;

MYSQL数据库 聚合函数与子查询
max(列)
表示求此列的最大值
例:

#求gender=1的id的最大值
select max(id) from students where gender=1;

MYSQL数据库 聚合函数与子查询
min(列)
表示求此列的最小值
(与max同理,在此不举例子了)

子查询
当我们在进行最大最小值查询时,想获得对应的其他信息时可用
例:

select * from students where id=(select min(id) from students where gender=1);

MYSQL数据库 聚合函数与子查询

sum(列)
表示求此列的和
例:

#查询男生(gender=1)id之和
select sum(id) from students where gender=1;

MYSQL数据库 聚合函数与子查询

avg(列)
表示求此列的平均值
例:

#查询群体学生的编号平均值
select avg(id) from students;

MYSQL数据库 聚合函数与子查询

相关文章:

  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
  • 2021-06-22
  • 2021-12-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
  • 2021-05-07
  • 2021-06-27
  • 2021-06-18
相关资源
相似解决方案