#常用的5个聚合函数 count(x)计数器,max(x)最大值min(最小值),avg(x)平均数,sum(x)求和
select count(*) from student where pwd is not null;
#max与min
select max(age) '最大年纪',min(age)'最小年纪' from student;
# 平均年龄
select avg(age) '平均年龄'from student;
# 年龄总和
select sum(age) '年龄总合' from student;
# 利用sum计算平均数
SELECT AVG(AGE)'平均年龄',sum(age)/(select count(*)from student)'sum的平均年龄'from student;
常用的五个聚合函数以及用法。
于 2024-03-29 10:32:11 首次发布
本文详细介绍了如何在SQL查询中使用常见的聚合函数count(),max(),min(),avg(),sum(),并以学生表为例,展示如何计算年龄的总数、最大值、最小值、平均值以及求和。还演示了如何通过sum函数计算平均数。
摘要由CSDN通过智能技术生成