聚合函数
select database();
用于查询当前连接的数据库名称。
对表中的数据进行统计和计算,一般结合分组(GROUPBY)来使用,用于统计和计算分组数据
COUNT()计算查询到了多少条数据
SUM()计算查珣结果中所有指定字段的和
AVG()计算查询结果中所有指定字段的平均值
MAX()求查询结果中指定字段的最大值
MIN()求查询结果中指定字段的最小值
select* from student;
select count(*)from student;
计算student表中所有的记录数,即表的总行数
select count(id) from student;
select sum(age) from student;
select avg(age) from student;
select max(sge) from student;
select min(age) from student;
--给查询出来的字段起别名
select count(*) as total from student;
- AS 是用于给查询结果列定义别名的关键字。
- total 是为 COUNT(*) 的统计结果设定的别名。通过这个别名,查询结果的列名会更清晰易读(显示为 total 而非 COUNT(*) )。
select count(*) total from student;
as可以省略,效果与上面一样

被折叠的 条评论
为什么被折叠?



