SQL聚合函数
2020-02-05 本文已影响0人
冷煖自知
count(*)
总数
select count(*) from person;
select count(*) from person where age=18;
max
最大值 min
最小值
select max(age) from person;
select min(id) from person where age=17;
sum
求和 avg
平均值(默认4位小数)
select sum(age) from person where gender=1;
select avg(age) from person where gender=1;
select sum(age)/count(*) from person where gender=1;
round
四舍五入
select round(avg(age),2) from person where gender=1;